目录
一、报错信息
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
描述: 无法将“ spring.datasource.password”下的属性绑定到java.lang.String: 原因:无法将“ spring.datasource.password”下的属性绑定到java.lang.String 行动: 更新您的应用程序的配置
二、方法1:配置检查
#jasypt加密的密匙(写到启动参数里面) jasypt: encryptor: password: qwert12345 algorithm: PBEWithMD5AndDES
三、方法2:更改pom引用jar版本
1)检查pom引用jar版本
<dependency> <groupId>com.github.ulisesbocchio</groupId> <artifactId>jasypt-spring-boot-starter</artifactId> <version>2.1.2</version> </dependency>
2)配置无误test重新生成
3)代码
package com.god.demo; import org.jasypt.encryption.StringEncryptor; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class EncryptTests { private static final String ALGORITHM_INFO = "PBEWithMD5AndDES"; private static final String PASSWORD_INFO = "qwert12345"; @Test void contextLoads() { } @Autowired StringEncryptor stringEncryptor; @Test public void encryptPwd() { StandardPBEStringEncryptor standardPBEStringEncryptor = new StandardPBEStringEncryptor(); //配置文件中配置如下的算法 standardPBEStringEncryptor.setAlgorithm(ALGORITHM_INFO); //配置文件中配置的password standardPBEStringEncryptor.setPassword(PASSWORD_INFO); //要加密的文本 String name = standardPBEStringEncryptor.encrypt("root"); String password = standardPBEStringEncryptor.encrypt("root"); String redisPassword = standardPBEStringEncryptor.encrypt("123456"); //将加密的文本写到配置文件中 System.out.println("name=" + name); System.out.println("password=" + password); System.out.println("redisPassword=" + redisPassword); //要解密的文本 String name2 = standardPBEStringEncryptor.decrypt("FarrmxSQX5uwtH/NZRxy+g=="); String password2 = standardPBEStringEncryptor.decrypt("vhiaYB1gl9zPj16yu7uMkA=="); String redisPassword2 = standardPBEStringEncryptor.decrypt("ZII7UphhbVuJ8c3oxPUeyw=="); //解密后的文本 System.out.println("name2=" + name2); System.out.println("password2=" + password2); System.out.println("redisPassword2=" + redisPassword2); } }
四、方法3:jar版本高版+新配置
有位同学加了补充,本人亲测可用。依旧使用3.0.3版本的添加如下配置即可。
因为官方在 3.0.0 以后更改了加密算法,所以假如你不设置的话,使用网上的方法加密出来的密码启动就会报错。
如图:
iv-generator-classname: org.jasypt.iv.NoIvGenerator
有用请点赞,养成良好习惯!
疑问、交流、鼓励请留言!
Failed to bind properties under ‘spring.datasource.password‘ to java.lang.String: Reason: Fail
于 2020-09-08 11:25:02 首次发布