【发布时间】:2020-09-02 12:20:19
【问题描述】:
我有一个 SpringBoot 应用程序,有一些附加的属性类用 @ConfigurationProperties 注释,而且,我还有一些配置。使用 @Configuration 注释的类。
放置 @EnableConfigurationProperties 注释的最佳位置是什么?我在主类上方看到它,但在配置上方。作为属性类的消费者的类,似乎是更好的放置位置,对我来说更有意义。放置此注释的最佳做法是什么?
例如:
@SpringBootApplication
//should it be here:
//@EnableConfigurationProperties(MyConfigProperties::class)
class MyApplication
fun main(args: Array<String>) {
runApplication<MyApplication>(*args)
}
@Configuration
//or here?
//@EnableConfigurationProperties(MyConfigProperties::class)
class MyConfig(
private val props: MyConfigProperties
){
// some methods, that uses props
}
@ConstructorBinding
@ConfigurationProperties("props")
data class MyConfigProperties(val myProp: String)
【问题讨论】:
标签: java spring spring-boot kotlin