spring配置文件加密
原文:http://www.open-open.com/code/view/1453520072183
通过继承spring配置类并重写处理方法实现密文解密
public class EncryptPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {
private String[] encryptPropNames = {"username", "password"};
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory,
Properties props) throws BeansException {
try {
for (int i = 0;i<encryptPropNames.length;i++){
String value = props.getProperty(encryptPropNames[i]);
if (value != null) {
props.setProperty(encryptPropNames[i],new String(DES.decrypt(new BASE64Decoder().decodeBuffer(value), "解密秘钥")));
}
}
super.processProperties(beanFactory, props);
} catch (Exception e) {
e.printStackTrace();
throw new BeanInitializationException(e.getMessage());
}
}
}
配置applicationContext.xml文件,并在jdbc.properties中设置密文(根据解密秘钥生成)
<!-- class填写刚才那段代码的类路径-->
<bean id="propertyConfigurer" class="com.**.EncryptPropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:jdbc.properties</value>
</list>
</property>
</bean>
spring配置文件加密的更多相关文章
- Spring cloud config配置文件加密解密
Spring cloud config配置文件加密解密 学习了:http://blog.csdn.net/u010475041/article/details/78110349 学习了:<Spr ...
- spring读取加密配置信息
描述&背景Spring框架配置数据库等连接等属性时,都是交由 PopertyPlaceholderConfigurer进行读取.properties文件的,但如果项目不允许在配置文件中明文保存 ...
- spring 配置文件 获取变量(PropertyPlaceholderConfigurer)
转自:https://hbiao68.iteye.com/blog/2031006 1.Spring的框架中,org.springframework.beans.factory.config.Prop ...
- 使用Jasypt对SpringBoot配置文件加密
# **前言** 在日前安全形势越来越严重的情况下,让我意识到在项目中存在一个我们经常忽略的漏洞,那就是我们的项目的配置文件中配置信息的安全,尤其是数据库连接的用户名和密码的安全.所以这里我们就需要对 ...
- SpringBoot进阶教程(六十三)Jasypt配置文件加密
数据库密码直接明文写在配置中,对安全来说,是一个很大的挑战.一旦密码泄漏,将会带来很大的安全隐患.尤其在一些企业对安全性要求很高,因此我们就考虑如何对密码进行加密.本文着重介绍Jasypt对Sprin ...
- 你不知道的Spring配置文件
Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".Java EE程序员必须学会并灵活应用这份"图纸&quo ...
- Spring配置文件详解
转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Sp ...
- Hibernate SQL方言 (hibernate.dialect) Spring配置文件applicationContext.xml
转自:http://www.cnblogs.com/wj-wangjun/archive/2009/10/21/1587624.html Hibernate SQL方言 (hibernate.dial ...
- Spring配置文件详解 - applicationContext.xml文件路径
spring的配置文件applicationContext.xml的默认地址在WEB-INF下,只要在web.xml中加入代码 org.springframework.web.context.Cont ...
随机推荐
- 输入防抖 vue # 输入搜索的时候 及时搜索的快速访问接口的 解决方案 vue 中使用防抖和节流
输入防抖 watch: { value (newVal, oldVal) { if (this.timer) { clearTimeout(this.timer) } this.timer = set ...
- es6 fs 输出文件 iviewDemo
// fs.open('./env.js', 'w', function(err, fd) { // // const buf = 'export default "development& ...
- 20道必须掌握的C++面试题
20道必须掌握的C++面试题 在面试C++方面的工作时,经常会遇到各种面试题,这对应聘人员的知识掌握能力要求较高.本文将为大家带来的就是20道必须掌握的C++面试题,不要错过哦! 问1:请用简单的语言 ...
- Activiti6简明教程
一.为什么选择Activiti 工作流引擎对比 二.核心7大接口.28张表 7大接口 (一)7大接口 RepositoryService:提供一系列管理流程部署和流程定义的API. RuntimeSe ...
- VIO第二讲_allen方差工具
1,首先,安装ceres依赖项,见高博14讲116页,然后下载编译安装ceres: git clone https://github.com/ceres-solver/ceres-solver cd ...
- java值的传递
public class Example { String str = new String("good"); char[] ch = {'a','b','c'}; public ...
- 深入理解typeof操作符
typeof可以检测数据的类型 typeof返回结果的其实是字符串:可以通过以下测试出来 console.log( typeof(typeof(a))); // string typeof返回的数据类 ...
- POJ-1328-放置雷达
这是一道贪心的题目,首先我们要知道,我们放置雷达的话我们可以做一个转换,就是已知岛屿的点坐标的时候,我们可以算一下,这个点以d为半径与x轴交点之间的线段在x轴上的投影,然后我们只需要在这个投影范围内设 ...
- Informatica抽取SQL Server数据库乱码
1.首先确认数据库的关系连接所使用的代码页,是否一致 2.如果上述方法不行,在Designer中更改数据类型,将string类型改为nstring类型,中文就没有乱码了 3.SQL Server数据库 ...
- phpstorm的全局操作快捷键ctrl+shift+f被搜狗占用处理方法
1.找到搜狗软件,右键选择属性设置 2.如图选择系统功能快捷键 3.去掉简繁切换快捷方式,确定后即可使用phpstorm的ctrl+shift+f来进行全局查找