How to map date/time properties from application.yml?

TuGordoBello :

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?

vins :

: 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"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=276733&siteId=1