今天公司大佬新建的项目上传打包测试,看到pom文件中这个包不认识,真是太难了,又得学习。
经过我的一番搜搜查查,得知这个包的用途是:给spring-boot项目中properties文件加密
可以给配置文件中的用户名和密码等敏感信息加密,然后我的一个同事就去问架构师大佬,为什么要加密?明文不也挺好的,到时候开发测试生产,也能分得清楚。大佬说自己想想。
https://github.com/ulisesbocchio/jasypt-spring-boot
官网给了四种引入方法,采用最简单的一种,加密数据库账号密码,实操一下
首先引入jar包:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
然后开始加密字符串获取密文,这里我采用maven插件的方式:
首先pom.xml文件中引入插件
<build>
<plugins>
<plugin>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-maven-plugin</artifactId>
<version>3.0.3</version>
</plugin>
</plugins>
</build>
然后执行maven命令:
mvn jasypt:encrypt-value -Djasypt.encryptor.password="thepassword" -Djasypt.plugin.value="theValueYouWantToEncrypt"
the password:设置的秘钥
theValueYouWantToEncrypt:加密的字符串
最后就可以改项目的配置文件了:
jasypt:
encryptor:
password: thepassword
spring:
datasource:
driver-class-name:
username:
password: ENC(Ik5OjHu6HMc/jVzPWBFBHIj7W/4JWRk3c+iDwJFuLEsRCu/nocQUOUjaY9xqF39t)
本以为可以完美启动了,但是启动报错:
Description:
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String