1 Problem Description
Use jasypt-spring-boot for encryption, but prompt:
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
Copy the code
Or tip
Description:
Failed to bind properties under 'spring.datasource.url' to java.lang.String:
Reason: Failed to bind properties under 'spring.datasource.password' to java.lang.String
Action:
Update your application's configuration
Copy the code
The final exception is this:
2 Solutions
I checked the relevant issue and found that 3.0.2 changed the default encryption algorithm. The final solution is to reduce the version to 2.1.2:
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>
Copy the code
Then re-encrypt the configuration, but 2.1.2 does not support the use of environment variables as encrypted passwords, which need to be added in the running configuration when testing in IDEA
-Djasypt.encryptor.password=xxxx
Copy the code
Add environment variables when deploying to Tomcat:
export JAVA_OPTS="-Djasypt.encryptor.password=xxxx"
Copy the code