1. Configure the properties file through spring
<bean id="propertyConfigurer"class="com.tjsoft.base.util.CustomizedPropertyPlaceholderConfigurer"><property name="ignoreResourceNotFound" value="true" /><property name="locations"><list><value>/WEB-INF/config/jdbc.properties</value><value>/WEB-INF/config/mail.properties</value><value>/WEB-INF/config/system.properties</value></list></property></bean>
Here, class is the defined class.
2. Custom class customizedpropertyplaceholderconfigurer
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;/*** custom propertyplaceholderconfigurer returns properties ** @ author LHY 2012-02-24 **/public class customizedpropertyplaceholderconfigurer extends {Private Static Map <string, Object> ctxpropertiesmap; @ overrideprotected void processproperties (abstrablelistablebeanfactory beanfactorytoprocess, properties props) throws beansexception {super. processproperties (beanfactorytoprocess, props); ctxpropertiesmap = new hashmap <string, Object> (); For (Object key: props. keyset () {string keystr = key. tostring (); string value = props. getproperty (keystr); ctxpropertiesmap. put (keystr, value) ;}} public static object getcontextproperty (string name) {return ctxpropertiesmap. get (name );}}
In this way, you can use the customizedpropertyplaceholderconfigurer class to obtain the content in the properties property file.
3. How to obtain the property File Content
String host = (string) customizedpropertyplaceholderconfigurer. getcontextproperty ("mail. SMTP. Host ");