在application.yml中为单个属性添加多个工期术语



在Spring Boot中,可以在application.yml中设置如下配置变量:

myprogram:
my-property: 5d # respectively 5 days

在代码中,它可以这样检索:

@ConfigurationProperties("myprogram")
public class MyProgramProperties {
@DurationUnit(ChronoUnit.SECONDS)
private Duration myProperty = Duration.ofSeconds(30); // default = 30 sec, if config var is not set
public Duration getMyProperty() {
return this.myProperty ;
}
public void setMyProperty(Duration myProperty ) {
this.myProperty = myProperty ;
}
}

但是有可能拥有以下内容吗?如果有,如何实现这一点:

myprogram:
my-property: 5d 3h 5m # respectively 5 days, 3 hours, 5 minutes

提前谢谢。

我不这么认为,您需要将其视为String,并使用单独的get方法来提取您想要的内容。

最新更新