简体   繁体   English

如何从 application.yml 映射时间属性?

[英]How to map time properties from application.yml?

I have problem mapping the time added on application.yml我在映射 application.yml 上添加的时间时遇到问题

bc:
  aop:
    core:
      boot:
        business:
          dailyStartHour: 08:00
          dailyEndHour: 17:00
          lunchStartHour: 12:00
          lunchEndHour: 13:00

this is muy java class这是 Muy Java 类

@Data
@Configuration
@ConfigurationProperties(prefix = "bc.aop.core.boot.business")
public class BusinessHourProperties {


    private String dailyStartHour;
    private String dailyEndHour;
    private String lunchStartHour;
    private String lunchEndHour;


}

but when I setup the application thrown a parse error但是当我设置应用程序时抛出了一个解析错误

Caused by: java.time.format.DateTimeParseException: Text '1020' could not be parsed at index 2
at java.time.format.DateTimeFormatter.parseResolved0(DateTimeFormatter.java:1949) ~[na:1.8.0_231]
at java.time.format.DateTimeFormatter.parse(DateTimeFormatter.java:1851) ~[na:1.8.0_231]
at java.time.LocalTime.parse(LocalTime.java:441) ~[na:1.8.0_231]
at java.time.LocalTime.parse(LocalTime.java:426) ~[na:1.8.0_231]
at pnc.aop.core.ofac.boot.BusinessDiscussionDate.discussion(BusinessDiscussionDate.java:26) ~[classes/:na]

The think is when I don't use BusinessHourProperties as a configuration like:想法是当我不使用BusinessHourProperties作为配置时:

private String dailyStartHour = "08:00";
private String dailyEndHour = "17:00";
private String lunchStartHour = "12:00";
private String lunchEndHour = "13:00";

I don't have problem.我没有问题。

What's happening?发生了什么?

: in your yaml value is causing this issue as yaml uses : for the key value mapping. :在您的 yaml 值中导致此问题,因为 yaml 使用:作为键值映射。 So change your properties in the yaml as shown here.因此,更改 yaml 中的属性,如下所示。

bc:
  aop:
    core:
      boot:
        business:
          dailyStartHour: "08:00"
          dailyEndHour: "17:00"
          lunchStartHour: "12:00"
          lunchEndHour: "13:00"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM