-
Notifications
You must be signed in to change notification settings - Fork 355
@Component/@Bean
with @ConfigurationProperties
does not work with Kotlin
#1679
Comments
@Component/@Bean
with @ConfigurationProperties
does not work@Component/@Bean
with @ConfigurationProperties
does not work with Kotlin
Hi! If you do a |
Yes, the following app works @SpringBootApplication
@ConfigurationPropertiesScan
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@ConstructorBinding
@ConfigurationProperties(prefix = "some.name")
data class SomeNameData(
var value: String = "",
)
@RequestMapping("hello")
@RestController
class HelloController(private val name: SomeNameData) {
@GetMapping
fun getName() = Mono.just("HELLO ${name.value}")
}
ok, the question was slightly different... need to check @SpringBootApplication
@ConfigurationPropertiesScan
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@Configuration
@EnableConfigurationProperties
class Config
@Component
@ConfigurationProperties(prefix = "some.name")
data class SomeNameData(
var value: String = "",
) it also does not @SpringBootApplication
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@Configuration
@EnableConfigurationProperties
class Config {
@Bean
fun data() = SomeNameData()
}
@ConfigurationProperties(prefix = "some.name")
data class SomeNameData(
var value: String = "",
) |
As there's a workaround by not annotating your configuration properties with |
But the problem is that it does not work only in spring native |
Yes, i understand that. But the problem you described has a workaround, and we are working on the native compilation story for Boot 3 / Spring Framework 6. When Spring Boot 3 is released, you won't need spring-native anymore, it's built into Boot itself. And there we strife to support your usecase. You can read more here |
That is what I needed to know, thank you :) |
Hi, I tried to find the example, but failed.
I have build my app - in various place I use combination like
@Component
or@Bean
, and@ConfigurationProperties
on the class (I use kotlin.In short, it is something like this
or (there without defining annotations on the class)
And for normal spring app it works fine.
But for
spring-native
I got following errorWith
@ConfigurationPropertiesScan
and@ConstructorBinding
as in examples - it works, but IMHO the solution with@Bean
is more configurable. Am I doing something wrong? Can something be done with that?The text was updated successfully, but these errors were encountered: