gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 08:52:35 26 4
gpt4 key购买 nike

我在映射 application.yml 上添加的时间时遇到问题

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

这是很多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;


}

但是当我设置应用程序时抛出解析错误

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]

我的想法是当我不使用 BusinessHourProperties 作为配置时,例如:

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

我没有问题。

发生了什么事?

最佳答案

yaml 值中的

: 导致此问题,因为 yaml 使用 : 作为键值映射。因此,请更改 yaml 中的属性,如下所示。

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

关于java - 如何从 application.yml 映射时间属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60689700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com