Spring 解析@Value属性内的LocalTime字符串

Spring 解析@Value属性内的LocalTime字符串,spring,spring-boot,environment-variables,localtime,Spring,Spring Boot,Environment Variables,Localtime,我的环境变量是一个字符串,时间是23:30。在我的字符串启动应用程序中,我想自动解析它,并将其设置为变量 我试过这样做 @Value("#{ java.time.LocalTime.parse('${NIGHT_START_TIME}')}") private LocalTime NIGHT_START_TIME; IntelliJ显示错误 无法解析变量“java” 这是日志 Unsatisfied dependency expressed through field 'NIGHT_START

我的环境变量是一个字符串,时间是23:30。在我的字符串启动应用程序中,我想自动解析它,并将其设置为变量

我试过这样做

@Value("#{ java.time.LocalTime.parse('${NIGHT_START_TIME}')}")
private LocalTime NIGHT_START_TIME;
IntelliJ显示错误

无法解析变量“java”

这是日志

Unsatisfied dependency expressed through field 'NIGHT_START_TIME';
nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'LocalTime' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public?
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
若我读像这样的变量,我会发现这个值是正确的

@Value("${NIGHT_START_TIME}")
private String NIGHT_START_TIME;
有什么办法让它工作吗?

试试这个

 @Value("#{ T(java.time.LocalTime).parse('${NIGHT_START_TIME}')}")
 private LocalTime NIGHT_START_TIME;
引用类的方式是使用T

检查。

试试这个

 @Value("#{ T(java.time.LocalTime).parse('${NIGHT_START_TIME}')}")
 private LocalTime NIGHT_START_TIME;
引用类的方式是使用T


检查。

已在弹簧靴2.2.6中检查。释放:

application.yml

服务

@Value("${NIGHT_START_TIME}")
private LocalTime NIGHT_START_TIME;

在没有任何膝部弯曲的情况下工作正常:

已在弹簧靴2.2.6中进行检查。释放:

application.yml

服务

@Value("${NIGHT_START_TIME}")
private LocalTime NIGHT_START_TIME;
完美工作,无任何膝盖弯曲: