Closed Azbesciak closed 2 years ago
Hi! If you do a @EnableConfigurationProperties(SomeNameData)
it works? It only doesn't work if you annotate it with @Component
?
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 It does not
@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 @Component
, this is unlikely to be fixed in Spring native, as this is in minimal maintenance mode. We'll look out for that usecase in the upcoming Boot 3 / Spring Framework 6 though.
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 thisor (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?