Failed to bind properties under ‘spring.datasource.password‘ to java.lang.String
作者:mmseoamin日期:2023-12-18
1、记录一次坑

在配置jasypt时,一些都很顺利,pom引入,项目启动。

从网上搜索资料jar包启动手动设置秘钥

java -jar -Djasypt.encryptor.password=1234qwer test.jar

但是在部署的时候,提示该错误。

***************************
APPLICATION FAILED TO START
***************************
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
Action:
Update your application's configuration

Failed to bind properties under ‘spring.datasource.password‘ to java.lang.String,在这里插入图片描述,第1张

2、查询资料

部署启动,报错。查找原因

1、检查配置,空格等。没有发现问题。

2、检查版本,版本为2.1.2,没有发现问题。

3、由于是设置了配置分离,端口等。将 Djasypt 配置放在 jar后面,依据报错。

3、分析报错

回过神来看报错信息

Failed to bind properties under ‘spring.datasource.password’ to java.lang.String

未能将“spring.datasource.password”下的属性绑定到java.lang.String

也就是说,我的这个配置不是个字符串咯。

于是将秘钥加个引号’

如下:

java -jar -Djasypt.encryptor.password='1234qwer' test.jar

完美解决问题。

4、总结

贴一下项目原本启动命令

nohup java -jar /app/web.jar --server.port=8080 --spring.config.location=/app/web.yml >> /app/web.out 2>&1 &

很简单的报错,却排查很久。

原因还是定势思维。不难发现,无论是port的配置,还是yml的配置,都没有对=之后的内容做处理,便可以直接识别。

还以之前的思维去考虑这个配置,就很难找到原因。

遇到类似的问题,不如清空脑袋,从问题源头,分析异常。范围更容易找到原因。

SpringBoot集成jasypt,加密yml配置文件:https://blog.csdn.net/qq_38254635/article/details/132026841

参考链接:

https://stackoverflow.com/questions/69255586/djasypt-encryptor-password-mavens-option-doesnt-work

https://www.cnblogs.com/nmdzwps/p/16291553.html

https://blog.csdn.net/libusi001/article/details/108465034

https://blog.csdn.net/weixin_43461040/article/details/125542216