ulisesbocchio / jasypt-spring-boot

Jasypt integration for Spring boot
MIT License
2.92k stars 523 forks source link

proxy-property-sources=true causes ClassCastException #369

Open greenarr0w opened 1 year ago

greenarr0w commented 1 year ago

Hello

I'm trying to use jasypt.encryptor.proxy-property-sources=true so that the PropertySources aren't wrapped, only proxied. We need this in our setup, because our internal framework has wrapped those PropertySources.

Versions: jasypt-spring-boot-starter:3.0.5 org.springframework.boot:2.7.14

Now I'm getting the following ClassCastException. The exception happens with a plain spring boot app with the jasypt-spring-boot-starter (first I thought it has something to do with our setup, but it doesn't seem like it):

org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tomcatServletWebServerFactory' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryConfiguration$EmbeddedTomcat.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'servletWebServerFactoryCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/ServletWebServerFactoryAutoConfiguration.class]: Unsatisfied dependency expressed through method 'servletWebServerFactoryCustomizer' parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'server-org.springframework.boot.autoconfigure.web.ServerProperties': Could not bind properties to 'ServerProperties' : prefix=server, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is java.lang.ClassCastException: class org.springframework.core.env.PropertiesPropertySource cannot be cast to class com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource (org.springframework.core.env.PropertiesPropertySource and com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource are in unnamed module of loader 'app')
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:165) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) ~[spring-context-5.3.29.jar:5.3.29]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.14.jar:2.7.14]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.14.jar:2.7.14]
    at com.example.demo.DemoApplicationKt.main(DemoApplication.kt:13) ~[main/:na]
nested exception is java.lang.ClassCastException: class org.springframework.core.env.PropertiesPropertySource cannot be cast to class com.ulisesbocchio.jasyptspringboot.EncryptablePropertySource 

Is this a known issue or is there a way to fix it?

Thank you in advance.