引言
最近公司给银行做了一个项目,在进行本地化部署的时候,银行的科技部门对我们的源码进行了安全扫描,在检测报告中有这么一个问题,要求我们的数据库密码不能以明文的 形式出现在配置文件中,所以小编需要解决这个问题,但是第一个想法就是,自己重写一个配置文件加载的那个方法,这样我们就可以在拿到密文以后,首先解密然后在使用。
但是查询了一些资料以后发现,这个问题已经有成熟的解决方案了,就是利用jasypt与spring结合轻松解决这个问题。
1、首先在项目中pom.xml文件中加入jasypt相关依赖包
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
2、在spring的xml文件中增加配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<!--基于环境变量,配置加密机-->
<bean id="environmentVariablesConfiguration"