Custom Propertyplaceholderconfigurer:
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 Springpropertyconfigurer extends Propertyplaceholderconfigurer {private static map<string, object& Gt
Ctxpropertiesmap;
@Override protected void Processproperties (Configurablelistablebeanfactory 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 map<string,Object> Getctxpropertiesmap () {return ctxpropertiesmap;
public static Object Getcontextproperty (String name) {return ctxpropertiesmap.get (name); }
}
Applicationcontext.xml Loading:
<bean id= "Propertyconfigurer" class= "Com.midea.jr.credit.accounting.utils.SpringPropertyConfigurer" lazy-init= "False" >
<property name= "Locations" >
<list>
<value>classpath:system.properties </value>
<value>classpath:redis.properties</value>
</list>
</property >
<property name= "fileencoding" value= "UTF-8"/>
</bean>
Read mode:
Private Springpropertyconfigurer propertyconfigurer;
@Override public
void Setservletcontext (ServletContext servletcontext) {
map<string, object> mvalue = Propertyconfigurer.getctxpropertiesmap ();
For (String Key:mValue.keySet ()) {
Logger.debug ("* * * Config application param: {" + key + ":" + mvalue.get (key) + " }*****" );
if (Key.startswith ("log")) {
System.setproperty (key, Mvalue.get (key). ToString ());
}
}
Output
2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * Config application param: {Jdbc.acquirecheckoutti meout:3000}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * * Config application param: {Redi S.pool.testonborrow:true}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * * Config Application Param: {redis.pool.maxidle:100}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * Config App Lication param: {redis.pool.maxactive:300}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * * * Config application param: {jdbc.maxidletime:2000}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG- Config application param: {redis.pass:1234xxxxx}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DE BUG-* * * Config application param: {dubbo.protocol.port:20880}***** 2016-07-06 17:44:33,529- -870 [Localhost-star TSTOP-1] DEBUG-* * * * *Config application param: {redis.pool.port:6379}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG- Config application param: {jdbc.maxpoolsize:20}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBU G-* * * * Config application param: {redis.maxactive:300}***** 2016-07-06 17:44:33,529- -870 [localhost-startstop-1] DEBUG-* * * Config application param: {redis.port:6379}*****