- extends PropertyPlaceholderConfigurer
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
public static Logger log=LoggerFactory.getLogger(EncryptPropertyPlaceholderConfigurer.class);
//设置需要解密的属性
private String[] encryptPropNames= {"jdbc.username","jdbc.password","jdbc.url"};
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
throws BeansException {
if(null!=encryptPropNames) {
try {
for(String propName : encryptPropNames) {
if(props.get(propName)!=null) {
props.setProperty(propName,AESUtil.decrypt(props.get(propName).toString()) );
}
}
} catch (RuntimeException | UnsupportedEncodingException e) {
log.info("执行失败");
}
}
super.processProperties(beanFactoryToProcess,props);
}
}
<!-- 加载多个配置文件 -->
<bean id="propertyConfigurer"
class="com.yltd.cnyun.sys.config.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:properties/sys_config.properties</value>
</list>
</property>
</bean>
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190612192330873.jpg?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FtZW5fV3U=,size_16,color_FFFFFF,t_70)