1. CustomPropertyConfigurer.java
package com.jdd.broker.admin.aspect;import java.util.HashMap;import java.util.Map;import java.util.Properties;import java.util.Map.Entry;import org.springframework.beans.BeansException;import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;import org.springframework.util.PropertyPlaceholderHelper; public class CustomPropertyConfigurer extends PropertyPlaceholderConfigurer{ private static Mapproperties = new HashMap (); protected void processProperties( ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException { // cache the properties PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper( DEFAULT_PLACEHOLDER_PREFIX, DEFAULT_PLACEHOLDER_SUFFIX, DEFAULT_VALUE_SEPARATOR, false); for(Entry
2. applicationContext.xml
classpath:/jdbc.properties
3. jdbc.properties
jdbc.driverClassName=com.mysql.jdbc.Driverjdbc.url=jdbc:mysql://rdsvl6l6emtdjrk6yi4k3public.mysql.rds.aliyuncs.com:3306/test_crowd?useUnicode=true&characterEncoding=utf8&allowMultiQueries=truejdbc.username=test_crowdjdbc.password=test_crowd
4. Main.java测试类
package com.jdd.broker.admin.aspect;import java.util.Map;import org.springframework.context.support.ClassPathXmlApplicationContext;public class Main {public static void main(String[] args) {new ClassPathXmlApplicationContext("spring-mvc.xml");Mapproperties = CustomPropertyConfigurer.getProperties();System.out.println(properties);}}