将ZonedDateTime绑定到application.properties中的bean

时间:2018-04-18 23:26:21

标签: spring-boot

我想通过application.properties将当前日期绑定到bean。我尝试使用拼写表达但它不起作用。

application.yml

defaults:
  date: #{T(java.time.ZonedDateTime).now()}

我有一个带有getter和setter的java bean。

@ConfigurationProperties(prefix = "defaults")
public class DefaultProperties {
    private ZonedDateTime date;

    // Getters & Setters
}

问题是表达式总是解析为字符串。我得到了Reason: Failed to convert property value of type 'java.lang.String' to required type 'java.time.ZonedDateTime'

有没有办法做到这一点?

0 个答案:

没有答案