【发布时间】:2017-03-06 17:01:03
【问题描述】:
假设如下配置bean:
@ConfigurationProperties(prefix="foo")
private class FooProperties {
private String mystring;
private int myint;
}
还有以下application.properties:
foo.mystring = ${bar.mystring}
foo.myint = ${bar.myint}
请注意,这两个属性无法解析,因为没有定义以 bar 开头的属性。以下是将会发生的事情:
-
foo.mystring设置为字符串"${bar.mystring}"(无分辨率) -
foo.myint将导致转换错误,因为字符串"${bar.myint}"无法转换为有效整数。
我希望在这种情况下会引发一种 Unresolvable Property 异常。就像我使用 @Value("${foo.mystring}") 会发生什么一样。
这是预期的行为吗? 在这种情况下,有没有办法让 SpringBoot 抛出这样的异常?
【问题讨论】:
标签: java spring spring-boot properties