spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support

Home Page:https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

michalkrajcovic opened this issue · comments

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

  • Spring Boot: 2.7.5
  • Spring Native: 0.12.1
  • GraalVM version : graalvm-ce-java17-22.3.0
  • JDK version: openjdk 17.0.5
  • Architecture: AMD64

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

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!