spring--给配置文件.properties加密
11111111111编写类并继承PropertyPlaceholderConfigurer.java
package com.xx.encryptDecrypt;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import com.xx.core.encrypt.EncryptUtil;
/**
* <br>
* Title:PropertyPlaceholderConfigurerExt <br>
* Description:PropertyPlaceholderConfigurer扩展
*/
public class PropertyPlaceholderConfigurerExt extends PropertyPlaceholderConfigurer {
private static Map<String, String> propertyMap;
private static Logger log = Logger.getLogger(PropertyPlaceholderConfigurerExt.class);
@Override
protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) throws BeansException {
propertyMap = new HashMap<String, String>();
String encryptNames = props.getProperty("encryptNames");
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
if (encryptNames.contains(keyStr)) {
try {
props.setProperty(keyStr, EncryptUtil.decrypt(value));
propertyMap.put(keyStr, EncryptUtil.decrypt(value));
} catch (Exception e) {
e.printStackTrace();
log.info("解密出错,配置文件的密文可能有误!!!!!!!!!1");
}
} else {
propertyMap.put(keyStr, value);
}
}
System.out.println(propertyMap.toString());
super.processProperties(beanFactoryToProcess, props);
}
// 自定义一个方法,即根据key拿属性值,方便java代码中取属性值
public static String getProperty(String name) {
return propertyMap.get(name);
}
}
22222222222---spring上下文配置
<bean id="propertyConfigurer" class="com.ytd.encryptDecrypt.PropertyPlaceholderConfigurerExt">
<property name="location" value="classpath:/conf/app.properties"/>
</bean>
3333333333---app.properties文件
账号密码改为密文
jdbc.username=bcc5b4b5174967b7
jdbc.password=bcc5b4b5174967b7
并添加键值对,作为解密标识
encryptNames=jdbc.username,jdbc.password
4444444444加密工具EncryptUtil.java不在贴出
spring--给配置文件.properties加密的更多相关文章
- Spring Boot 配置文件密码加密两种方案
Spring Boot 配置文件密码加密两种方案 jasypt 加解密 jasypt 是一个简单易用的加解密Java库,可以快速集成到 Spring 项目中.可以快速集成到 Spring Boot 项 ...
- spring boot 配置文件properties和YAML详解
spring boot 配置文件properties和YAML详解 properties中配置信息并获取值. 1:在application.properties配置文件中添加: 根据提示创建直接创建. ...
- spring*.xml配置文件明文加密
spring*.xml配置文件明文加密 说明:客户要求spring*.xml中Oracle/Redis/MongoDB的IP.端口.用户名.密码不能明文存放,接到需求的我,很无奈,但是还是的硬着头皮搞 ...
- spring jdbc配置文件进行加密解密
最近做一个项目,安全上有点要求,就是要对数据库相关的配置进行加密,配置文件如下: #加密前#datasource.type=mysql #datasource.driverClassName=com. ...
- Java中如何获取spring中配置文件.properties中属性值
通过spring配置properties文件 1 2 3 4 5 6 7 8 9 <bean id="propertyConfigurer" class="co ...
- spring boot 配置文件加密数据库用户名/密码
这篇文章为大家分享spring boot的配置文件properties文件里面使用经过加密的数据库用户名+密码,因为在自己做过的项目中,有这样的需求,尤其是一些大公司,或者说上市公司,是不会把这些敏感 ...
- java Spring使用配置文件读取jdbc.properties
Spring使用配置文件读取jdbc.properties 在beans.xml中加入两个必须的bean [html]<bean id="propertyConfigurer" ...
- 【转】spring管理属性配置文件properties——使用PropertiesFactoryBean|spring管理属性配置文件properties——使用PropertyPlaceholderConfigurer
spring管理属性配置文件properties--使用PropertiesFactoryBean 对于属性配置,一般采用的是键值对的形式,如:key=value属性配置文件一般使用的是XXX.pr ...
- Spring boot 配置文件详解 (properties 和yml )
从其他框架来看 我们都有自己的配置文件, hibernate有hbm,mybatis 有properties, 同样, Spring boot 也有全局配置文件. Springboot使用一个全局的配 ...
随机推荐
- How the heck does async/await work in Python 3.5
https://snarky.ca/how-the-heck-does-async-await-work-in-python-3-5/
- 在github上搭建个人博客
1.平台注册账号,新建域名 github(源码托管服务站):https://github.com/到GitHub官网,注册自己的账号,填好用户名,密码,邮箱,并完成邮箱验证就可以啦!默认的域名是htt ...
- React+Webpack+Webstorm开发环境搭建
需要安装的软件 node.js npm包管理 Webstorm 由于6.3.0版本之后会自带npm的包管理所以不需要单独的安装npm nodejs(包含npm)安装在默认路径C:\Program Fi ...
- [转]springboot2 webflux 响应式编程学习路径
原文链接 spring官方文档 springboot2 已经发布,其中最亮眼的非webflux响应式编程莫属了!响应式的weblfux可以支持高吞吐量,意味着使用相同的资源可以处理更加多的请求,毫无疑 ...
- tensorflow中一种融合多个模型的方法
1.使用场景 假设我们有训练好的模型A,B,C,我们希望使用A,B,C中的部分或者全部变量,合成为一个模型D,用于初始化或其他目的,就需要融合多个模型的方法 2.如何实现 我们可以先声明模型D,再创建 ...
- 认识 SSH 密钥对
SSH 密钥对是阿里云为您提供的新的远程登录 ECS 实例的认证方式. 相较于传统的用户名和密码认证方式,SSH 密钥对有以下特点: 仅适用于 Linux 实例: SSH 密钥对登录认证更为安全可靠: ...
- Nginx 配置参数详解
#定义Nginx运行的用户和用户组 user www www; #nginx进程数,建议设置为等于CPU总核心数. worker_processes 8; #全局错误日志定义类型,[ debu ...
- redis数据操作笔记
redis是key-value的数据结构,每条数据都是一个键值对键的类型是字符串 注意:键不能重复,值的类型分为五种:字符串string 哈希hash 列表list 集合set 有序集合zset 一. ...
- Linux系统Vi/Vim编辑器的简单介绍、安装/卸载、常用命令
Linux系统Vi/Vim编辑器的简单介绍.安装/卸载.常用命令 1.介绍 vi(Visual Interface)编辑器是Linux和Unix上最基本的文本编辑器,工作在字符模式下.由于不需要图形界 ...
- C# 不安装Oracle客户端情况下,如何连接到Oracle数据库
简介: 在我们开发应用场景经常碰到需要连接Oracle数据库,这也是相当常见的一种情况.一般.Net环境连接Oracle数据库,可以通过TNS/SQL.NET 配置文件,而 TNS 必须要 Oracl ...