PropertyPlaceholderConfigurer 使用方法
spring-plugins.xml文件中
<!-- load properties -->
<bean id="propertyConfigurer" class="com.rskj.core.util.PropertyPlaceholder">
<property name="locations">
<list>
<value>classpath:config/*.properties</value>
</list>
</property>
</bean>
其中com.rskj.core.util.PropertyPlaceholder对应为com.rskj.core.util包下的PropertyPlaceholder.java文件
package com.rskj.core.util;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class PropertyPlaceholder extends PropertyPlaceholderConfigurer {
private static Map<String,String> propertyMap;
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
super.processProperties(beanFactoryToProcess, props);
propertyMap = new HashMap<String, String>();
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
propertyMap.put(keyStr, value);
}
}
public static String getProperty(String name) {
return propertyMap.get(name);
}
}
使用:
String source_props = PropertyPlaceholder.getProperty("source");