spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 356 forks source link

ConfigurationPropertiesBindException is thrown when properties class uses @ConstructorBinding in multi-module gradle spring boot project #1731

Closed michalkrajcovic closed 1 year ago

michalkrajcovic commented 1 year ago

Describe the bug

org.springframework.boot.context.properties.ConfigurationPropertiesBindException is thrown when properties class uses @ConstructorBinding in multi-module gradle spring boot project.

I’m reporting it as a bug as I can’t see any issues reported, nor documented that this is not supported in native image.

To Reproduce Environment

Sample project https://github.com/michalkrajcovic/spring-native-multi-modules-bind-properties

Compile

./gradlew nativeCompile

Run

./greetings-app/build/native/nativeCompile/greetings-app

Fails with

2022-11-10 09:52:10.860  WARN 11168 --- [           main] o.s.c.support.GenericApplicationContext  : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'application': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.boot.context.properties.ConfigurationPropertiesBindException: Error creating bean with name 'greetings-com.example.greetings.configuration.GreetingsProperties': Could not bind properties to 'GreetingsProperties' : prefix=greetings, ignoreInvalidFields=false, ignoreUnknownFields=true; nested exception is org.springframework.boot.context.properties.bind.BindException: Failed to bind properties under 'greetings' to com.example.greetings.configuration.GreetingsProperties
Description:
Failed to bind properties under 'greetings' to com.example.greetings.configuration.GreetingsProperties:
    Reason: java.lang.IllegalStateException: Failed to extract parameter names for public com.example.greetings.configuration.GreetingsProperties(java.lang.String)
Action:
Update your application's configuration

Runs without issues on JVM

./gradlew bootRun

Expected behavior Application starts without issues using JVM and native image.

Observation Does not fail when properties class uses setters see brach setter. ConstructorBinding doesn't fail in single module project see branch single-module

mhalbritter commented 1 year ago

Hello,

spring-native is in minimal maintenance mode. Please try your use case with Spring Boot 3.x and if it still breaks, please open an issue on the corresponding issue tracker (Spring Boot in this case). Thanks!