【发布时间】:2021-12-12 23:21:15
【问题描述】:
我正在使用 SpringBoot。
在以前的项目中,我使用的是 application.property 文件,内容看起来像这样:
seconds.timeOut=10
interval.milliseconds.cleaner=#{${seconds.timeOut}*2*1000}
interval.seconds.cleanerOffset=#{${seconds.timeOut}*3}
结果是正确的cleaner=20000 和cleanerOffset=30
在新项目中,我切换到 application.yml 文件。具有相同的配置:
seconds:
timeOut: 10
interval:
milliseconds:
cleaner: ${seconds.timeOut}*2*1000
interval:
seconds:
cleanerOffset: ${seconds.timeOut}*3
但结果是字符串清洁器 = "10*2*1000" 当然我也有例外:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'cleaningWorker': Invalid fixedDelayString value "10*2*1000" - cannot parse into long
我找不到任何解决方法,你能帮我吗?
【问题讨论】:
-
您是否已经尝试将
#{${seconds.timeOut}*2*1000}作为 YAML 文件中的值? -
这能回答你的问题吗? Use SpringBoot SpEL in YAML
-
是的,我尝试 #{${seconds.timeOut}*2*1000} 但这不起作用!
-
@blurfus 谢谢这正是我正在寻找的。span>