Spring Boot cannot bind spring.datasource.password with Jasypt ENC() values
Failed to bind properties under 'spring.datasource.password' to java.lang.StringShort answer
The binding error means Jasypt could not turn the ENC(...) value back into plain text. The usual reasons are that the encryptor password never reached the app (common in Docker), the value was encrypted with a different algorithm or IV generator than the app now uses, or the library version does not match your Spring Boot version.
Fix it fast
1Find out which cause you have
Find the root cause at the bottom of the stack trace and see whether the app received the encryptor password at all. The password is a setting, not part of the encrypted value.
docker compose logs app | grep -i -E "jasypt|Caused by" docker compose exec app printenv JASYPT_ENCRYPTOR_PASSWORD2Match what you see, then jump to its fix
- 1
printenv prints nothing inside the container, or the property jasypt.encryptor.password is empty.The encryptor password never reached the applicationFix - 2
The password is present, but decryption still fails for a value created by another tool, an older project or an older library version.The value was encrypted with different settings than the app decrypts withFix - 3
The failure starts after a Spring Boot or Java upgrade, with no change to the encrypted values.The Jasypt library does not match the Spring Boot or Java versionFix
- 1
What does the error look like?
Failed to bind properties under 'spring.datasource.password' to java.lang.String
Cause 1 of 3
The encryptor password never reached the application
1Check
The password is the one required Jasypt setting and should not sit in a property file. It can be passed as a system property, a command-line argument or an environment variable; for the environment variable the config must map it to ${JASYPT_ENCRYPTOR_PASSWORD:}.
grep -R -n "jasypt.encryptor" src/main/resources/2Fix
Map the variable with a placeholder in the configuration (Spring Boot resolves ${name:default} placeholders against the environment) and pass it when the container starts.
# application.properties
jasypt.encryptor.password=${JASYPT_ENCRYPTOR_PASSWORD:}
# docker-compose.yml
services:
app:
environment:
JASYPT_ENCRYPTOR_PASSWORD: ${JASYPT_ENCRYPTOR_PASSWORD}3Verify
The variable is visible inside the container and the app starts without the binding error.
docker compose exec app printenv JASYPT_ENCRYPTOR_PASSWORDConfirmed by github.com
Cause 2 of 3
The value was encrypted with different settings than the app decrypts with
1Check
The defaults are algorithm PBEWITHHMACSHA512ANDAES_256, 1000 key-obtention iterations, a random salt generator and a random IV generator. The project notes that defaults may change between versions. Settings used at encryption time must match the ones at runtime.
grep -R -n -E "jasypt.encryptor" src/main/resources/ docker-compose.yml2Fix
Encrypt the value again with the same library and the same settings the app uses, using the Jasypt Maven plugin (jasypt-maven-plugin, added to the pom), and paste the result between ENC( and ).
mvn jasypt:encrypt-value -Djasypt.encryptor.password="$JASYPT_ENCRYPTOR_PASSWORD" -Djasypt.plugin.value="db-password"3Verify
Put the new ENC(...) value into spring.datasource.password and restart the app.
docker compose up -d --build appConfirmed by github.com
Cause 3 of 3
The Jasypt library does not match the Spring Boot or Java version
1Check
The current jasypt-spring-boot requires Java 17 or newer and Spring Boot 3.5 or newer. List the library version your build resolves.
mvn dependency:tree | grep -i jasypt2Fix
Upgrade the jasypt-spring-boot dependency to a release that supports your Spring Boot version; if encrypted values stop decrypting after the upgrade, re-encrypt them with the plugin as in the previous cause.
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version><!-- a release that supports your Spring Boot version --></version>
</dependency>3Verify
The dependency tree shows the new version and the app starts.
mvn dependency:tree | grep -i jasyptConfirmed by github.com
How do I stop it coming back?
- Never keep the encryptor password in the same repository or image as the ENC() values.
- Write down the algorithm and IV generator you used next to the encrypted value, so a later upgrade can match them.
- Test the container start with the same environment variables the real deployment uses.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Apache HttpClient 5 has no setSSLSocketFactory on HttpClients.custom()
HttpClients.custom().setSSLSocketFactory() method not found
In Apache HttpClient 5 the TLS setup no longer sits on the client builder.
2 causes, each with a fixBack end
A scanner flags jackson-databind: how to upgrade it in Gradle
jackson-databind vulnerability reported by a dependency scanner
Find where the old jackson-databind comes from, then raise it.
3 causes, each with a fixBack end
Gradle cannot resolve spring-boot-gradle-plugin after a Spring Boot 3 upgrade
Plugin [id: 'org.springframework.boot', version: '3.0.1'] was not found in any of the following sources
Spring Boot 3 needs Java 17 or newer and a recent Gradle, and its Gradle plugin is published on the Gradle Plugin Portal.
3 causes, each with a fixBack end
bootJar cannot find the main class of a Spring Boot project
Main class name has not been configured and it could not be resolved
The Spring Boot Gradle plugin looks in the main source set's output for a class with a public static void main method.
2 causes, each with a fixBack end
Spring Boot fails at startup with an error processing a condition on an auto-configuration
java.lang.IllegalStateException: Error processing condition on org.springframework.boot.autoconfigure.jdbc.JndiDataSourceAutoConfiguration
This message only says Spring Boot failed while evaluating an auto-configuration condition.
3 causes, each with a fixBack end
Swagger UI URL shows the Whitelabel Error Page in Spring Boot
Whitelabel Error Page when opening /swagger-ui.html
The Whitelabel page means Spring found no handler for that address.
3 causes, each with a fix