使用ConfigurationProperties
绑定属性时,无法正确解析属性扩展。或者更具体地说,当不存在要扩展的属性时,绑定不会失败,并且将属性名称用作值。
让我们看看以下情况
// The binding class
open class MyProperties {
lateinit var myValue: String
}
// The configuration
@Configuration
@EnableConfigurationProperties
class MyConfig {
@Bean
@ConfigurationProperties(prefix = "my.properties")
fun myProperties(): MyProperties = MyProperties()
}
## The spring properties yaml
my.properties:
my-value: ${my.another.value}
当存在正在扩展的属性my.another.value
时,则该值存在于MyProperties#myValue
中;但是,当属性my.another.value
不存在时,会将原始字符串"${my.another.value}"
加载到MyProperties#myValue
中。
是否有一种方法可以迫使应用程序尝试扩展属性(并且无法启动),而不是使用扩展表达式作为值?