이전에 묻는 질문처럼 보일 수 있지만 다른 문제가 있습니다.정적 필드에 스프링 주입 값을 설정하는 방법
정적 메서드 만있는 유틸리티 클래스가 있습니다. 나는하지 않으며 나는 그것에서 예를 들어 가지 않을 것이다. 이미 다른 콩에서 일을하지만
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
<util:properties id="dataBaseAttr"
location="file:#{classPathVariable.path}/dataBaseAttr.properties" />
</beans>
이 클래스 (의 Utils) 여기에 문제가되지 않습니다 : 내가 데이터베이스와 dataBaseAttr을 채우기 위해 봄을 필요로 지금
public class Utils{
private static Properties dataBaseAttr;
public static void methodA(){
}
public static void methodB(){
}
}
는 Properties.Spring의 설정은 속성 그리고 만약 내가 bean을 아무것도 만들지 않는다면 클래스가 인스턴스화되지 않고 변수가 항상 null과 같기 때문에 변수를 사용할 수 없다.
고마워, 당신은 정말 내 일 저장. –
당신은 오신 것을 환영합니다! –
나는 그것을 잘 이해하지 못했기 때문에 첫 번째 해결책을 시도하지 않았다. 제 2의 솔루션을 시도하고 잘됐다. –