1. maven添加相应版本的依赖
这里注意,不能使用太新的版本,本人开发环境使用3.0.3版本时,报以下错误,使用2.1.2时报错消失。
*************************** application failed to start *************************** description: failed to bind properties under 'spring.datasource.dynamic.datasource.master.password' to java.lang.string: reason: org.springframework.boot.context.properties.bind.bindexception: failed to bind properties under 'spring.datasource.dynamic.datasource.master.password' to java.lang.string action: update your application's configuration disconnected from the target vm, address: '127.0.0.1:56043', transport: 'socket'
2. 更新maven依赖
更新后,到仓库中找到加密工具jasypt-1.9.3.jar
3. 使用jasypt工具生成密文
java -cp jasypt-1.9.3.jar org.jasypt.intf.cli.jasyptpbestringencryptioncli input=待加密字符串 password=盐 algorithm=pbewithmd5anddes
4. 修改application-dev.yml文件中待加密的数据源密码
enc(ftvdryjcycwdfnpfxus8sw==)
5. 编辑配置,增加项目启动参数
-djasypt.encryptor.password=1234
或者 application.yml 文件中增加jasypt的盐配置项:
jasypt: encryptor: password: 1234
6. 启动调试项目
可以看到日志中,数据库连接成功,项目启动成功。
到此这篇关于idea中springboot项目数据库连接加密方法的文章就介绍到这了,更多相关springboot数据库连接加密内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论