属性扩展未与配置属性类正确绑定

时间:2020-08-20 09:03:20

标签: spring spring-boot kotlin yaml

使用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中。

是否有一种方法可以迫使应用程序尝试扩展属性(并且无法启动),而不是使用扩展表达式作为值?

0 个答案:

没有答案
相关问题