英文:
Create an object using @Value
问题
I'm trying to use @Value annotation to read a string parameter value and create an object using this value.
I've tried the following:
The parameter in application.yml
app:
report:
time-zone: +00:00
Creating the object using the parameter:
@Value("#{ java.time.ZoneId.of('app.report.time-zone') }")
ZoneId reportZoneId;
But got the error:
Unsatisfied dependency expressed through field 'reportZoneId':
Expression parsing failed
Is something wrong with the syntax or isn't it possible at all?
英文:
I'm trying to use @Value annotation to read a string parameter value and create an object using this value.
I've tried the following:
The parameter in application.yml
app:
report:
time-zone: +00:00
Creating the object using the parameter:
@Value("#{ java.time.ZoneId.of('app.report.time-zone') }")
ZoneId reportZoneId;
But got the error:
> Unsatisfied dependency expressed through field 'reportZoneId':
> Expression parsing failed
Is something wrong with the syntax or isn't it possible at all?
答案1
得分: 3
这是正确的语法:
@Value("#{T(java.time.ZoneId).of('${app.report.time-zone}')}")
ZoneId reportZoneId;
英文:
This is the correct syntax for the case:
@Value("#{T(java.time.ZoneId).of('${app.report.time-zone}')}")
ZoneId reportZoneId;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论