Version: Springboot 3.0.0 the @ConstructorBinding annotation does not work with the Kotlin primary constructor. The Annotation is written on the class itself and produces the error "This annotation is not applicable to target 'class'".
Comment From: mhalbritter
This is documented here: https://kotlinlang.org/docs/classes.html#secondary-constructors
If the constructor has annotations or visibility modifiers, the constructor keyword is required and the modifiers go before it:
For example:
@ConfigurationProperties("application")
class CtorBinding @ConstructorBinding constructor(val x: String, val y: String) {
override fun toString(): String {
return "CtorBinding(x='$x', y='$y')"
}
}
Comment From: vinh-hoang
Hi, thanks for the response. In version 2.7.x it works like this (example from baeldung):
@ConfigurationProperties(prefix = "api")
@ConstructorBinding
data class ApiConfiguration(
val clientId: String,
val url: String,
val key: String
)
So I assume this style will not be supported anymore?
Comment From: mhalbritter
This is documented here: https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-3.0-Migration-Guide#constructingbinding-no-longer-needed-at-the-type-level
In your case you can drop the @ConstructorBinding because Spring Boot is now clever enough to use the constructor without any annotations.