Get the Properties property names and property values that are configured in spring

Source: Internet
Author: User
Tags redis

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}*****


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.