-
Notifications
You must be signed in to change notification settings - Fork 40.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Constructor binding of @ConfigurationProperties to a Kotlin Data Class with default values doesn't work any more #32416
Comments
Thanks for the report. It looks like these changes to |
@wilkinsona which version has this fix? I've tried 3.0.0-RC2 and the issue is still there. My data class: @ConfigurationProperties("foo.locale")
data class LocaleProperties @ConstructorBinding constructor(
val default: String = "en-US",
val supported: List<String> = listOf()
) the exception I get:
|
As shown by the milestone to which this issue is assigned, the fix was made in 3.0.0-M5. I don't think you need |
@wilkinsona The issue seems to be back as of 3.0.5. The following data class:
causes an exception during Spring context creation:
Adding an explicit no-args constructor without the annotation fixes the issue, but is unwieldy (brevity is an important selling point for using data classes for configuration properties, after all).
Behavior is the same for |
@mkosmul As per my comment immediately before yours, I don't think you need to use |
Hmm... As of Spring Boot v3.1.2: import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
@Component
@ConfigurationProperties("app.someProps")
class SomeProps(
val someProp: Boolean = true
)
strikes again. |
@green-green-avk Can you please open a new issue for this and provide a complete reproducer that we can run and debug? |
For anyone searching for this and discovering this issue via google: I.e. this works for me on spring boot 3.2.2: @Configuration
@EnableConfigurationProperties(SomeProps::class)
class CorsConfiguration {
}
@ConfigurationProperties(prefix = "myproject.cors")
data class SomeProps(
val enabled: Boolean = false,
) And this doesn't: @Configuration
//@EnableConfigurationProperties(SomeProps::class)
class CorsConfiguration {
}
@Component
@ConfigurationProperties(prefix = "myproject.cors")
data class SomeProps(
val enabled: Boolean = false,
) This version throws:
Switch to the first version to make it work with |
Hello π ,
I searched for a similar issue, but didn't find one so I chose to open itβ¦ If I've missed it, sorry π.
Following modification of
@ConstructingBinding
in 3.0.0-M1, I had to remove the annotation from ourConfigurationProperties
classes:With this, the application fails to start with the following error
Because of the Kotlin nature, there is multiple constructors generated to support default values defined. I've tried to use the annotation on the constructor like this
but the result is not working too, for a different reason
The only way to make it working was to use the
@ConstructorBinding constructor(β¦)
with no default values⦠which is something we would like to avoid of course.Thank you for your help on this subject.
The text was updated successfully, but these errors were encountered: