学习日志:对DB.properties文件使用DES加密,通过重写PropertyPlaceholderConfigurer类对properties文件进行解密,然后Mybatis读取spring DataResource。
配置文件如下:
classpath:DB.properties
PropertyPlaceholderConfigurer 重写如下:
public class MyPropertyLoader extends PropertyPlaceholderConfigurer {
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)
throws BeansException {
String url = (String) props.getProperty("url");
String username = props.getProperty("username");
String password = props.getProperty("password");
String pw = PassWord.getPassWord();
try {
url = MyEncrypt.decryptString(url,pw);
username = MyEncrypt.decryptString(username,pw);
password = MyEncrypt.decryptString(password,pw);
props.setProperty("url", url);
props.setProperty("username", username);
props.setProperty("password", password);
} catch (Exception e) {
e.printStackTrace();
}
//props.get(arg0)
super.processProperties(beanFactoryToProcess, props);
}
}
版权声明:本文为z294155673原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。