Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key/value形式)文件中 
一些动态设定的值(value),在XML中替换为占位该键($key$)的值, 
.properties文件可以根据客户需求,自定义一些相关的参数,这样的设计可提供程序的灵活性。

xml中的配置文件

<bean id="propertyConfigurer"
class="com.datasure.util.filter.EncryptablePropertyPlaceholderConfigurer">
<property name="locations">
<list><value>classpath:jdbc.properties</value></list>
</property>
</bean>
public class EncryptablePropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private static final String key = "helloworld"; protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
try {
Des des = new Des();
String username = props.getProperty("jdbc.username");
if (username != null) {
props.setProperty("jdbc.username", des.Decrypt(username, des.hex2byte(key)));
} String password = props.getProperty("jdbc.password");
if (password != null) {
props.setProperty("jdbc.password", des.Decrypt(password, des.hex2byte(key)));
} String url = props.getProperty("jdbc.url");
if (url != null) {
props.setProperty("jdbc.url", des.Decrypt(url, des.hex2byte(key)));
} String driverClassName = props.getProperty("jdbc.driverClassName");
if(driverClassName != null){
props.setProperty("jdbc.driverClassName", des.Decrypt(driverClassName, des.hex2byte(key)));
} super.processProperties(beanFactory, props);
} catch (Exception e) {
e.printStackTrace();
throw new BeanInitializationException(e.getMessage());
}
}
}

通过如上配置就可以对配置文件进行解密操作

最新文章

  1. 【repost】JavaScript Scoping and Hoisting
  2. LeakCanary 内存检测 工具 --超级傻瓜 不会DDMS的福音
  3. hdu5033 Building (单调栈+)
  4. hdoj 5358 First One
  5. 掌握 Java 8 Lambda 表达式
  6. LeetCode_Convert Sorted Array to Binary Search Tree
  7. python中的I/O
  8. 面向对象(java菜鸟的课堂笔记)
  9. flask 数据库迁移的简单操作
  10. 转自:stuff字符串拼接方法
  11. Linux进程管理 (7)实时调度
  12. 微软和Sun针对Java的世纪之战
  13. 面试:C++String类实现
  14. Linux相关知识总结
  15. Java实例---简单的宠物管理系统
  16. centos添加php及mysql环境变量
  17. 导入工程“The import android cannot be resolved”错误
  18. [hdu6435]Problem J. CSGO
  19. 转:Eclipse常见问题,快捷键收集
  20. 2019-9-11:渗透测试,基础学习,vim编辑器,笔记

热门文章

  1. 深入理解JavaScript系列(32):设计模式之观察者模式
  2. 浅谈前端与SEO
  3. 搭建Vue2.0开发环境
  4. 在 Linux 上创建第一个 Service Fabric Java 应用程序
  5. 课堂笔记&amp;总结与遇错纠错篇
  6. JS的封装(JS插件的封装)
  7. OPENCV VS设置
  8. 【IOS】Mac和IOS开发资源汇总
  9. Quartus II管脚批量分配文件(.tcl)格式
  10. Spark天堂之门解密