标签:
public class SpringPropertyConfigurer extends PropertyPlaceholderConfigurer { private static Map<String, String> ctxPropertiesMap; @Override protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)throws BeansException { super.processProperties(beanFactory, props); ctxPropertiesMap = new HashMap<String, String>(); for (Object key : props.keySet()) { String keyStr = key.toString(); String value = props.getProperty(keyStr); ctxPropertiesMap.put(keyStr, value); } } //static method for accessing context properties public static String getContextProperty(String name) { return ctxPropertiesMap.get(name); } }
配置文件:
<!-- 加载PROPERTY配置文件 -->
<bean id="propertySource" class="com.mediaforce.news.api.utils.SpringPropertyConfigurer">
<property name="order" value="2" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="fileEncoding">
<value>UTF-8</value>
</property>
<property name="locations">
<list>
<value>classpath:message.properties</value>
<value>classpath:sysconfig.properties</value>
</list>
</property>
</bean>
读取配置文件 PropertyPlaceholderConfigurer 的配置与使用
标签:
原文地址:http://www.cnblogs.com/amei0/p/4736791.html