英文:
How to map time properties from application.yml?
问题
在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";
我就没有问题。发生了什么?
英文:
I have problem mapping the time added on application.yml
bc:
aop:
core:
boot:
business:
dailyStartHour: 08:00
dailyEndHour: 17:00
lunchStartHour: 12:00
lunchEndHour: 13:00
this is muy java class
@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:
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?
答案1
得分: 2
:
在你的 YAML 值中引起了这个问题,因为 YAML 使用 :
用于键值映射。所以按照这里的示例更改你的 YAML 属性。
bc:
aop:
core:
boot:
business:
dailyStartHour: "08:00"
dailyEndHour: "17:00"
lunchStartHour: "12:00"
lunchEndHour: "13:00"
英文:
:
in your yaml value is causing this issue as yaml uses :
for the key value mapping. So change your properties in the yaml as shown here.
bc:
aop:
core:
boot:
business:
dailyStartHour: "08:00"
dailyEndHour: "17:00"
lunchStartHour: "12:00"
lunchEndHour: "13:00"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论