I am using Jasypt in my Spring Boot app and encrypted passwords in app properties and docker-compose using proper annotation:
application.properties.yml:
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/employee_db
username: postgres
password: ENC(fpEVpMwMbl4hbcoCKuhrpi...)
# jasypt
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
docker-compose.yml:
services:
db:
image: postgres:14.6-alpine
environment:
POSTGRES_DB: employee_db
POSTGRES_USER: postgres
POSTGRES_PASSWORD: ENC(fpEVpMwMbl4hbcoCKuhrpi...)
After creating Docker image for database (db container), I add the VM options to IntelliJ and start the app. But I got the following error and cannot find a solution for that:
Description: Failed to bind properties under ‘spring.datasource.password’ to java.lang.String:
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under ‘spring.datasource.password’ to java.lang.String
Action: Update your application’s configuration
Any idea to solve the problem?
Here is the full log:
C:Userssimpson.jdkscorretto-17.0.5binjava.exe -Djasypt.encryptor.password=abnamro -XX:TieredStopAtLevel=1 -Dspring.output.ansi.enabled=always -Dcom.sun.management.jmxremote -Dspring.jmx.enabled=true -Dspring.liveBeansView.mbeanDomain -Dspring.application.admin.enabled=true "-javaagent:C:Program FilesJetBrainsIntelliJ IDEA 2022.2.1libidea_rt.jar=53749:
C:Program FilesJetBrainsIntelliJ IDEA 2022.2.1bin" -Dfile.encoding=UTF-8 -classpath "D:employee-apitargetclasses;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-data-jpa2.7.5spring-boot-starter-data-jpa-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-aop2.7.5spring-boot-starter-aop-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-aop5.3.23spring-aop-5.3.23.jar;C:Userssimpson.m2repositoryorgaspectjaspectjweaver1.9.7aspectjweaver-1.9.7.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-jdbc2.7.5spring-boot-starter-jdbc-2.7.5.jar;C:Userssimpson.m2repositorycomzaxxerHikariCP4.0.3HikariCP-4.0.3.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-jdbc5.3.23spring-jdbc-5.3.23.jar;C:Userssimpson.m2repositoryjakartatransactionjakarta.transaction-api1.3.3jakarta.transaction-api-1.3.3.jar;C:Userssimpson.m2repositoryjakartapersistencejakarta.persistence-api2.2.3jakarta.persistence-api-2.2.3.jar;C:Userssimpson.m2repositoryorghibernatehibernate-core5.6.12.Finalhibernate-core-5.6.12.Final.jar;C:Userssimpson.m2repositoryorgjbossloggingjboss-logging3.4.3.Finaljboss-logging-3.4.3.Final.jar;C:Userssimpson.m2repositorynetbytebuddybyte-buddy1.12.18byte-buddy-1.12.18.jar;C:Userssimpson.m2repositoryantlrantlr2.7.7antlr-2.7.7.jar;C:Userssimpson.m2repositoryorgjbossjandex2.4.2.Finaljandex-2.4.2.Final.jar;C:Userssimpson.m2repositoryorghibernatecommonhibernate-commons-annotations5.1.2.Finalhibernate-commons-annotations-5.1.2.Final.jar;C:Userssimpson.m2repositoryorgglassfishjaxbjaxb-runtime2.3.7jaxb-runtime-2.3.7.jar;C:Userssimpson.m2repositoryorgglassfishjaxbtxw22.3.7txw2-2.3.7.jar;C:Userssimpson.m2repositorycomsunistackistack-commons-runtime3.0.12istack-commons-runtime-3.0.12.jar;C:Userssimpson.m2repositorycomsunactivationjakarta.activation1.2.2jakarta.activation-1.2.2.jar;C:Userssimpson.m2repositoryorgspringframeworkdataspring-data-jpa2.7.5spring-data-jpa-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkdataspring-data-commons2.7.5spring-data-commons-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-orm5.3.23spring-orm-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-context5.3.23spring-context-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-tx5.3.23spring-tx-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-beans5.3.23spring-beans-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-aspects5.3.23spring-aspects-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-web2.7.5spring-boot-starter-web-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter2.7.5spring-boot-starter-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-logging2.7.5spring-boot-starter-logging-2.7.5.jar;C:Userssimpson.m2repositorychqoslogbacklogback-classic1.2.11logback-classic-1.2.11.jar;C:Userssimpsson.m2repositorychqoslogbacklogback-core1.2.11logback-core-1.2.11.jar;C:Userssimpson.m2repositoryorgapachelogginglog4jlog4j-to-slf4j2.17.2log4j-to-slf4j-2.17.2.jar;C:Userssimpson.m2repositoryorgapachelogginglog4jlog4j-api2.17.2log4j-api-2.17.2.jar;C:Userssimpson.m2repositoryorgslf4jjul-to-slf4j1.7.36jul-to-slf4j-1.7.36.jar;C:Userssimpson.m2repositoryjakartaannotationjakarta.annotation-api1.3.5jakarta.annotation-api-1.3.5.jar;C:Userssimpson.m2repositoryorgyamlsnakeyaml1.30snakeyaml-1.30.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-json2.7.5spring-boot-starter-json-2.7.5.jar;C:Userssimpson.m2repositorycomfasterxmljacksoncorejackson-databind2.13.4.2jackson-databind-2.13.4.2.jar;C:Userssimpson.m2repositorycomfasterxmljacksoncorejackson-annotations2.13.4jackson-annotations-2.13.4.jar;C:Userssimpson.m2repositorycomfasterxmljacksondatatypejackson-datatype-jdk82.13.4jackson-datatype-jdk8-2.13.4.jar;C:Userssimpson.m2repositorycomfasterxmljacksondatatypejackson-datatype-jsr3102.13.4jackson-datatype-jsr310-2.13.4.jar;C:Userssimpson.m2repositorycomfasterxmljacksonmodulejackson-module-parameter-names2.13.4jackson-module-parameter-names-2.13.4.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-tomcat2.7.5spring-boot-starter-tomcat-2.7.5.jar;C:Userssimpson.m2repositoryorgapachetomcatembedtomcat-embed-core9.0.68tomcat-embed-core-9.0.68.jar;C:Userssimpson.m2repositoryorgapachetomcatembedtomcat-embed-websocket9.0.68tomcat-embed-websocket-9.0.68.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-web5.3.23spring-web-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-webmvc5.3.23spring-webmvc-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-expression5.3.23spring-expression-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-starter-validation3.0.0spring-boot-starter-validation-3.0.0.jar;C:Userssimpson.m2repositoryorgapachetomcatembedtomcat-embed-el9.0.68tomcat-embed-el-9.0.68.jar;C:Userssimpson.m2repositoryorghibernatevalidatorhibernate-validator6.2.5.Finalhibernate-validator-6.2.5.Final.jar;C:Userssimpson.m2repositoryjakartavalidationjakarta.validation-api2.0.2jakarta.validation-api-2.0.2.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-devtools2.7.5spring-boot-devtools-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot2.7.5spring-boot-2.7.5.jar;C:Userssimpson.m2repositoryorgspringframeworkbootspring-boot-autoconfigure2.7.5spring-boot-autoconfigure-2.7.5.jar;C:Userssimpson.m2repositoryorgprojectlomboklombok1.18.24lombok-1.18.24.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-boot-starter3.0.0springfox-boot-starter-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-oas3.0.0springfox-oas-3.0.0.jar;C:Userssimpson.m2repositoryioswaggercorev3swagger-annotations2.1.2swagger-annotations-2.1.2.jar;C:Userssimpson.m2repositoryioswaggercorev3swagger-models2.1.2swagger-models-2.1.2.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-spi3.0.0springfox-spi-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-schema3.0.0springfox-schema-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-core3.0.0springfox-core-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-spring-web3.0.0springfox-spring-web-3.0.0.jar;C:Userssimpson.m2repositoryiogithubclassgraphclassgraph4.8.83classgraph-4.8.83.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-spring-webmvc3.0.0springfox-spring-webmvc-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-spring-webflux3.0.0springfox-spring-webflux-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-swagger-common3.0.0springfox-swagger-common-3.0.0.jar;C:Userssimpson.m2repositoryorgmapstructmapstruct1.3.1.Finalmapstruct-1.3.1.Final.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-data-rest3.0.0springfox-data-rest-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-bean-validators3.0.0springfox-bean-validators-3.0.0.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-swagger23.0.0springfox-swagger2-3.0.0.jar;C:Userssimpson.m2repositoryioswaggerswagger-annotations1.5.20swagger-annotations-1.5.20.jar;C:Userssimpson.m2repositoryioswaggerswagger-models1.5.20swagger-models-1.5.20.jar;C:Userssimpson.m2repositoryiospringfoxspringfox-swagger-ui3.0.0springfox-swagger-ui-3.0.0.jar;C:Userssimpson.m2repositorycomfasterxmlclassmate1.5.1classmate-1.5.1.jar;C:Userssimpson.m2repositoryorgslf4jslf4j-api1.7.36slf4j-api-1.7.36.jar;C:Userssimpson.m2repositoryorgspringframeworkpluginspring-plugin-core2.0.0.RELEASEspring-plugin-core-2.0.0.RELEASE.jar;C:Userssimpson.m2repositoryorgspringframeworkpluginspring-plugin-metadata2.0.0.RELEASEspring-plugin-metadata-2.0.0.RELEASE.jar;C:Userssimpson.m2repositoryorgapachecommonscommons-text1.10.0commons-text-1.10.0.jar;C:Userssimpson.m2repositoryorgapachecommonscommons-lang33.12.0commons-lang3-3.12.0.jar;C:Userssimpson.m2repositorycomgithubulisesbocchiojasypt-spring-boot-starter3.0.3jasypt-spring-boot-starter-3.0.3.jar;C:Userssimpson.m2repositorycomgithubulisesbocchiojasypt-spring-boot3.0.3jasypt-spring-boot-3.0.3.jar;C:Userssimpson.m2repositoryorgjasyptjasypt1.9.3jasypt-1.9.3.jar;C:Userssimpson.m2repositoryorgflywaydbflyway-core9.8.3flyway-core-9.8.3.jar;C:Userssimpson.m2repositorycomfasterxmljacksondataformatjackson-dataformat-toml2.13.4jackson-dataformat-toml-2.13.4.jar;C:Userssimpson.m2repositorycomfasterxmljacksoncorejackson-core2.13.4jackson-core-2.13.4.jar;C:Userssimpson.m2repositoryorgpostgresqlpostgresql42.5.1postgresql-42.5.1.jar;C:Userssimpson.m2repositoryorgcheckerframeworkchecker-qual3.5.0checker-qual-3.5.0.jar;C:Userssimpson.m2repositoryjakartaxmlbindjakarta.xml.bind-api2.3.3jakarta.xml.bind-api-2.3.3.jar;C:Userssimpson.m2repositoryjakartaactivationjakarta.activation-api1.2.2jakarta.activation-api-1.2.2.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-core5.3.23spring-core-5.3.23.jar;C:Userssimpson.m2repositoryorgspringframeworkspring-jcl5.3.23spring-jcl-5.3.23.jar" com.demo.EmployeeApiApplication
19:35:35.056 [Thread-0] DEBUG org.springframework.boot.devtools.restart.classloader.RestartClassLoader - Created RestartClassLoader org.springframework.boot.devtools.restart.classloader.RestartClassLoader@4a79e7d6
2022-12-10 19:35:35,468 INFO com.demo.EmployeeApiApplication : Starting EmployeeApiApplication using Java 17.0.5 on DESKTOP-1J43AAP with PID 27224 (D:Archive_HRApplicationsInterviewABN Amroassignmentsolutionemployee-apitargetclasses started by simpson in D:Archive_HRApplicationsInterviewABN Amroassignmentsolutionemployee-api)
2022-12-10 19:35:35,468 DEBUG com.demo.EmployeeApiApplication : Running with Spring Boot v2.7.5, Spring v5.3.23
2022-12-10 19:35:35,469 INFO com.demo.EmployeeApiApplication : The following 1 profile is active: "production"
2022-12-10 19:35:36,533 INFO com.ulisesbocchio.jasyptspringboot.configuration.EnableEncryptablePropertiesBeanFactoryPostProcessor : Post-processing PropertySource instances
2022-12-10 19:35:36,549 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource configurationProperties [org.springframework.boot.context.properties.source.ConfigurationPropertySourcesPropertySource] to AOP Proxy
2022-12-10 19:35:36,550 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource servletConfigInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,550 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource servletContextInitParams [org.springframework.core.env.PropertySource$StubPropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource systemProperties [org.springframework.core.env.PropertiesPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource systemEnvironment [org.springframework.boot.env.SystemEnvironmentPropertySourceEnvironmentPostProcessor$OriginAwareSystemEnvironmentPropertySource] to EncryptableSystemEnvironmentPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource random [org.springframework.boot.env.RandomValuePropertySource] to EncryptablePropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource Config resource 'class path resource [application.yml]' via location 'optional:classpath:/' [org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,551 INFO com.ulisesbocchio.jasyptspringboot.EncryptablePropertySourceConverter : Converting PropertySource devtools [org.springframework.core.env.MapPropertySource] to EncryptableMapPropertySourceWrapper
2022-12-10 19:35:36,579 INFO com.ulisesbocchio.jasyptspringboot.filter.DefaultLazyPropertyFilter : Property Filter custom Bean not found with name 'encryptablePropertyFilter'. Initializing Default Property Filter
2022-12-10 19:35:36,703 INFO com.ulisesbocchio.jasyptspringboot.resolver.DefaultLazyPropertyResolver : Property Resolver custom Bean not found with name 'encryptablePropertyResolver'. Initializing Default Property Resolver
2022-12-10 19:35:36,704 INFO com.ulisesbocchio.jasyptspringboot.detector.DefaultLazyPropertyDetector : Property Detector custom Bean not found with name 'encryptablePropertyDetector'. Initializing Default Property Detector
2022-12-10 19:35:36,923 INFO org.apache.catalina.core.StandardService : Starting service [Tomcat]
2022-12-10 19:35:36,923 INFO org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.68]
2022-12-10 19:35:36,979 INFO org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2022-12-10 19:35:37,053 INFO com.ulisesbocchio.jasyptspringboot.encryptor.DefaultLazyEncryptor : Found Custom Encryptor Bean org.jasypt.encryption.pbe.PooledPBEStringEncryptor@220275ac with name: jasyptStringEncryptor
2022-12-10 19:35:37,082 INFO org.apache.catalina.core.StandardService : Stopping service [Tomcat]
2022-12-10 19:35:37,114 ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'spring.datasource.password' to java.lang.String:
Reason: org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'spring.datasource.password' to java.lang.String
Action:
Update your application's configuration
Process finished with exit code 0
I run the project using IntelliJ IDEA by selecting Run
-> Edit Configurations
and in the Build and run
section, add the following value to the VM options field and run the application: -Djasypt.encryptor.password=my-secret
2
Answers
Try to downgrade to 2.0.0 version of jasypt-spring-boot-starter