我在下面的spring配置中使用來自java Classess的文件中的訪問權限。 有對JavaEE的項目很多方面類似如下:如何在Java SE項目中使用PropertyPlaceholderConfigurer
<context:component-scan base-package="com.service.pack" />
<context:property-placeholder properties-ref="appProperties"/>
我可以使用上面的Java SE項目,以試圖PropertyPlaceholderConfigurer類的方法,但在這個時候applicationProperties豆不是從PropertyPlaceholderConfigurer類見過這麼propertiesMap爲空。
我在做什麼錯?有沒有從類文件一樣的JavaEE accecing屬性的簡單執行的項目
<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 props參數爲null時,爲什麼? –