【发布时间】:2018-02-07 11:31:40
【问题描述】:
事情是这样的,我想在我的 Dynamo 表中添加 ttl,它有一个默认的 Duration,但我希望它可以通过属性进行配置,以便每个 Spring Profile 都有自己的配置。
public Long getTtl() {
return ttl;
}
public void setTtl(Long ttl) {
this.ttl = ttl;
}
为了正确填充它,我需要做这样的事情。
entity.setTtl(Instant.now().plus(Duration.from(defaultTTL)).getEpochSecond());
我会从@Value 或其他东西加载这个默认TTL。
但我的问题是放在哪里。我的第一直觉是在默认构造函数中设置,但我不喜欢在其中加载 Spring 值。
遵循“一起改变的代码,属于一起”。
我错了吗?
【问题讨论】: