【发布时间】:2015-05-06 10:06:21
【问题描述】:
我们实际上使用 Spring Boot 的 @ConfigurationProperties 作为基本的配置映射器:它为我们提供了一个简单的快捷方式来映射对象的属性。
@ConfigurationProperties("my.service")
public class MyService {
private String filePrefix;
private Boolean coefficient;
private Date beginDate;
// getters/setters mandatory at the time of writing
public void doBusinessStuff() {
// ...
}
}
虽然这在我们为应用程序设计原型时大大提高了生产力,但我们开始质疑这是否正确使用。
我的意思是,配置属性在 Spring Boot 的上下文中具有不同的状态,它们通过执行器端点公开,它们可用于触发条件 bean,并且似乎更倾向于技术配置属性。
问题:在任何商业财产/价值上使用这种机制是否“正确”,还是完全滥用?
我们错过了任何潜在的缺点吗?
现在我们唯一担心的是我们不能在不可变类上使用@ConfigurationProperties,这与Spring Boot的跟踪器上的这个问题密切相关:Allow field based @ConfigurationProperties binding
【问题讨论】:
标签: java configuration spring-boot