Spring Properties 读取 PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer
@Service("propertyPlaceholder")publicclassPropertyPlaceholderextendsPropertyPlaceholderConfigurer{privatestaticMap<String,String>propertyMap;@OverrideprotectedvoidprocessProperties(ConfigurableListableBeanFactorybeanFactoryToProcess,Propertiesprops)throwsBeansException{super.processProperties(beanFactoryToProcess,props);propertyMap=newHashMap<String,String>();for(Objectkey:props.keySet()){StringkeyStr=key.toString();Stringvalue=props.getProperty(keyStr);propertyMap.put(keyStr,value);}}//staticmethodforaccessingcontextpropertiespublicObjectgetProperty(Stringname){returnpropertyMap.get(name);}}
xml
<beanclass="com.lxzl.config.PropertyPlaceholder"><propertyname="location"><value>classpath:config.properties</value></property></bean>
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。