Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

Spring Boot cannot bind spring.datasource.password with Jasypt ENC() values

ErrorFailed to bind properties under 'spring.datasource.password' to java.lang.String

Short 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.

  • Applies to jasypt-spring-boot 3.x, Spring Boot 3, Java 21, Docker
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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_PASSWORD
  2. 2Match what you see, then jump to its fix

    1. 1printenv prints nothing inside the container, or the property jasypt.encryptor.password is empty.The encryptor password never reached the applicationFix
    2. 2The 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. 3The 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

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_PASSWORD

Confirmed by github.com

Did this fix it?

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.yml

2Fix

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 app

Confirmed by github.com

Did this fix it?

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 jasypt

2Fix

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 jasypt

Confirmed by github.com

Did this fix it?

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.