参考http://blog.csdn.net/zhangt85/article/details/42122311
<bean id="propertyConfigurer"
class="com.pingan.ecological.util.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath*:*.properties</value>
</list>
</property>
<property name="fileEncoding" value="GBK" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
EncryptPropertyPlaceholderConfigurer.java
import java.util.Properties;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanInitializationException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private static Logger logger = LogManager.getLogger(EncryptPropertyPlaceholderConfigurer.class);
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
try {
String passwordKey = "jdbc.password";
String password = props.getProperty(passwordKey);
if (password != null) {
props.setProperty(passwordKey, DESUtils.getDecryptString(password));
}
super.processProperties(beanFactory, props);
} catch (Exception e) {
logger.error("processProperties", e);
throw new BeanInitializationException(e.getMessage());
}
}
}