【转载】加密Spring加载的Properties文件
目标:要加密spring的jdbc配置文件的密码口令。
实现思路:重写加载器的方法,做到偷梁换柱,在真正使用配置之前完成解密。
1.扩展
package com.rail.comm;
import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
/**
*
* 项目名称:rwoa
* 类名称:PropertyPlaceholderConfigurerExt
* 类描述: 对数据库用户名密码加密
* 创建人:赵井桂
* 创建时间:2012-5-17 上午10:45:27
* 修改人:赵井桂
* 修改时间:2012-5-17 上午10:45:27
* 修改备注:
* @version
*
*/
public class PropertyPlaceholderConfigurerExt extends PropertyPlaceholderConfigurer{
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
throws BeansException {
String username=props.getProperty("datasource.username");
String password = props.getProperty("datasource.password");
//解密jdbc.password属性值,并重新设置
props.setProperty("datasource.username",Util.decrypt(username));
props.setProperty("datasource.password",Util.decrypt(password));
super.processProperties(beanFactory, props);
}
}
2.Spring配置文件修改
//无加密
<!-- <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">-->
//加密后的
<bean id="placeholderConfig" class="com.rail.comm.PropertyPlaceholderConfigurerExt">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
3.init.properties 文件修改
datasource.type=mysql
datasource.driverClassName=com.mysql.jdbc.Driver
datasource.url=jdbc:mysql://192.168.1.46:3306/rwoadb?useUnicode=true&characterEncoding=utf-8
datasource.username=2CCEE362A852387BD51C63E4780F2588
datasource.password=984027EDC2227C8EAF5D9733178C6418
4.加密算法实现,这里就不在赘述。
【转载】加密Spring加载的Properties文件的更多相关文章
- 解密Spring加载的Properties文件
Spring的框架中,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer类可以将.properties(key ...
- SpringMVC加载配置Properties文件的几种方式
最近开发的项目使用了SpringMVC的框架,用下来感觉SpringMVC的代码实现的非常优雅,功能也非常强大, 网上介绍Controller参数绑定.URL映射的文章都很多了,写这篇博客主要总结一下 ...
- 【Java Web开发学习】Spring加载外部properties配置文件
[Java Web开发学习]Spring加载外部properties配置文件 转载:https://www.cnblogs.com/yangchongxing/p/9136505.html 1.声明属 ...
- Eclipse下SpringBoot没有自动加载application.properties文件
Eclipse内创建SpringBoot项目,在java/main/resources文件夹下面创建application.properties配置文件,SpringApplication.run后发 ...
- 【转载】Spring加载resource时classpath*:与classpath:的区别
免责声明: 本文转自网络文章,转载此文章仅为个人收藏,分享知识,如有侵权,请联系博主进行删除. 原文作者:kyfxbl 原文地址: spring配置中classpath和cla ...
- Java实现动态加载读取properties文件
问题: 当我们使用如下语句加载.properties时: ClassLoader classLoader = this.getClass().getClassLoader(); Properties ...
- spring加载hibernate映射文件的几种方式。转自:http://blog.csdn.net/huiwenjie168/article/details/7013618
在Spring的applicationContext.xml中配置映射文件,通常是在<sessionFactory>这个Bean实例中进行的,若配置的映射文件较少时,可以用sessionF ...
- java web项目启动时自动加载自定义properties文件
首先创建一个类 public class ContextInitListener implements ServletContextListener 使得该类成为一个监听器.用于监听整个容器生命周期的 ...
- spring加载hibernate映射文件的几种方式 (转)
在Spring的applicationContext.xml中配置映射文件,通常是在<sessionFactory>这个 Bean实例中进行的,若配置的映射文件较少时,可以用session ...
随机推荐
- 《马上有招儿:PPT商务演示精选20讲(全彩) 》
<马上有招儿:PPT商务演示精选20讲(全彩) > 基本信息 作者:马建强 霍然 出版社:电子工业出版社 ISBN:9787121225123 上架时间:2014-3-11 出版日期 ...
- eclipse无法启动
-startupplugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar-showsplashorg.eclipse.platfo ...
- scala编程第17章学习笔记(4)——元组
元组可以把固定数量的条目组合在一起以便于作为整体传送.不像数组或列表,元组可以保存不同类型的对象. 元组常用来返回方法的多个值.例如,下面的方法找到集合中的最长单词并返回它的索引: scala> ...
- data-stream-as-disjoint-intervals
https://leetcode.com/problems/data-stream-as-disjoint-intervals/ /** * Definition for an interval. * ...
- C#调用C++ memcpy实现各种参数类型的内存拷贝 VS marshal.copy的实现 效率对比
using System; using System.Runtime.InteropServices; using System.IO; namespace tx { struct ST { publ ...
- [leetcode]Single Number II @ Python
原题地址:http://oj.leetcode.com/problems/single-number-ii/ 题意:Given an array of integers, every element ...
- 一步步教你如何在 Visual Studio 2013 上使用 Github
介绍 我承认越是能将事情变简单的工具我越会更多地使用它.尽管我已经知道了足够的命令来使用Github,但我宁愿它被集成到IDE中.在本教程中,我会告诉你使用Visual Studio 2013如何实现 ...
- 火速提升Android仿真器的运行速度 ——仿真器Genymotion
一.问题概述 Android开发中会使用仿真器测试应用,但不管你使用Eclispe ADT还是Android Studio仿真器都是基于arm架构的,运行起来都很慢,光启动就要花费很多时间,都不知道它 ...
- file not found app文件
昨天svn迁移.然后又一次check out之后编译遇到这个错误. Ld Build/Products/Debug-iphonesimulator/wiseCloudCrmTests.xctest/w ...
- Transform导入数据源TR1008错误
cognos在建设初期开发者们都常常遇到的一个问题,在这里做一下小小的总结. iqd作为Transform的数据源导入数据的时候遭遇TR1008错误 注意: 从报错的内容可以看出transform不能 ...