@Service("propertyPlaceholder") 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); } } //static method for accessing context properties public Object getProperty(String name) { return propertyMap.get(name); } }
xml
<bean class="com.lxzl.config.PropertyPlaceholder"> <property name="location"> <value>classpath:config.properties</value> </property> </bean>
Spring Properties 读取 PropertyPlaceholderConfigurer
原文地址:http://blog.51cto.com/xinzhilian/2052823