Chr*_*now 5 cron groovy spring spring-el
我正在尝试设置一个 cron Scheduled 注释,如下所示:
@Scheduled(cron = "#{systemEnvironment['db_cron']}")
def void schedule() {
}
Run Code Online (Sandbox Code Playgroud)
接下来将环境变量设置为:
export db_cron="0 19 21 * * *"
Run Code Online (Sandbox Code Playgroud)
但是,我收到运行时错误:
Cron expression must consist of 6 fields
(found 1 in "#{systemEnvironment['db_cron']}")
Run Code Online (Sandbox Code Playgroud)
会出什么问题?
编辑
我也试过: @Scheduled(cron = "${db_cron}")
但这会返回编译时错误:
/Users/snowch/repos/sales/Prospects/Snow/Plugwise/etl_service/src/main/groovy/com/ibm/etl/Application.groovy: 52: Expected '$db_cron' to be an inline constant of type java.lang.String in @org.springframework.scheduling.annotation.Scheduled
@ line 52, column 23.
@Scheduled(cron = "${db_cron}")
^
/Users/snowch/repos/sales/Prospects/Snow/Plugwise/etl_service/src/main/groovy/com/ibm/etl/Application.groovy: -1: Attribute 'cron' should have type 'java.lang.String'; but found type 'java.lang.Object' in @org.springframework.scheduling.annotation.Scheduled
@ line -1, column -1.
2 errors
:compileGroovy FAILED
FAILURE: Build failed with an exception.
Run Code Online (Sandbox Code Playgroud)
我试过了 @Scheduled(cron = "#{db_cron}")
但是运行时错误是:
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: static org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.setSystemPropertiesMode() is applicable for argument types: (java.lang.Integer) values: [2]
Possible solutions: setSystemPropertiesMode(int), setSystemPropertiesModeName(java.lang.String)
at groovy.lang.MetaClassImpl.invokeStaticMissingMethod(MetaClassImpl.java:1373)
at groovy.lang.MetaClassImpl.invokeStaticMethod(MetaClassImpl.java:1359)
at org.codehaus.groovy.runtime.callsite.StaticMetaClassSite.call(StaticMetaClassSite.java:50)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.ibm.etl.Application.main(Application.groovy:43)
Run Code Online (Sandbox Code Playgroud)
注意环境变量设置如下:
snowch$ echo "$db_cron"
0 19 21 * * *
Run Code Online (Sandbox Code Playgroud)
您应该像这样设置 env 变量:
export db_cron="0 19 21 * * *"
Run Code Online (Sandbox Code Playgroud)
如果您正在使用或重新启动终端会话,请重新启动您的IDE。
@Scheduled(cron = "${db_cron}")
def void schedule() {
...
}
Run Code Online (Sandbox Code Playgroud)
我尝试过,这是我的屏幕截图。一切都按预期进行......
| 归档时间: |
|
| 查看次数: |
10170 次 |
| 最近记录: |