Java Classess의 파일에서 액세스 속성을 사용하려면 아래의 스프링 구성을 사용해야합니다. 다음과 같은 JavaEE 어플 프로젝트를위한 여러 가지 방법이 있습니다 :Java SE 프로젝트에서 PropertyPlaceholderConfigurer를 사용하는 방법
나는 자바 SE 프로젝트 때문에 시도 PropertyPlaceholderConfigurer와 클래스의 방법이지만 상기 propertiesMap가 null 있도록 applicationProperties 콩 PropertyPlaceholderConfigurer와 클래스에서 보이지 않는이 시간에 사용할 수 있어요<context:component-scan base-package="com.service.pack" />
<context:property-placeholder properties-ref="appProperties"/>
.
내가 뭘 잘못하고 있니? JavaEE 어플 같은 클래스 파일에서 속성을 accecing의 간단한 방법은 당신이 뭘 하려는지 모르겠지만 위의 샘플 프로젝트에서, PropertiesUtil
이 PropertyPlaceholderConfigurer
에서 확장하지만 XML 구성이 PropertyPlaceholderConfigurer
을 의미
<bean id="applicationProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:app.properties"/>
</bean>
@Component
public class PropertiesUtil extends PropertyPlaceholderConfigurer {
private static Map<String, String> propertiesMap;
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory,
Properties props) throws BeansException {
super.processProperties(beanFactory, props);
propertiesMap = new HashMap<String, String>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
propertiesMap.put(keyStr, parseStringValue(props.getProperty(keyStr),
props, new HashSet()));
}
}
public static String getProperty(String name) {
return (String) propertiesMap.get(name);
}
}
Jave SE 프로젝트에서 왜 다른가 ... 차이점은 없습니다 ... –
processProperties (메소드가 호출되면 Properties 소문자 매개 변수가 null 일 때) 이유는 무엇입니까? –