Consider the following Kotlin data class for holding ConfigurationProperties:
@ConstructorBinding
@ConfigurationProperties
data class MyProps(
@DataSizeUnit(DataUnit.MEGABYTES)
val dataLimit: DataSize
)
Since the convert annotations such as @DataSizeUnit
are field level annotations, and the ValueObjectBinder
class is only looking for constructor parameter annotations, these convert annotations will not be processed and configuration data will not be converted properly. No error or warning is issued in the logs and the user is left to debug through Spring code for hours to find the issue! 😄
Possible solutions:
1. Search field level annotations on Kotlin data classes as well as constructor annotations.
2. Allow convert annotations to be placed on constructor parameters
Comment From: encircled
Hi,
As of now, @ConfigurationProperties
support injection via setter only, regardless of whether it is written in Kotlin or Java. Looks like a good improvement to me, I will prepare a PR.
Comment From: snicoll
As of now, @ConfigurationProperties support injection via setter only, regardless of whether it is written in Kotlin or Java
@encircled that's not accurate. We have constructor injection for both Kotlin and Java.
Comment From: encircled
Right, I forgot about ConstructorBinding
. Let me check it again
Comment From: mbhave
Closing in favor of PR #21746.