Cron表达式必须包含6个字段(在#{systemEnvironment ['db_cron']}“中找到1) [英] Cron expression must consist of 6 fields (found 1 in "#{systemEnvironment['db_cron']}")
问题描述
@Scheduled(cron =#{systemEnvironment [ 'db_cron']})
def void schedule(){
}
接下来将环境变量设置为:
export db_cron =0 19 21 * * *
但是,我得到运行时错误:
Cron表达式必须包含6个字段
(在#{systemEnvironment ['db_cron']}中找到1)
有什么可能会出错?
编辑 我也试过: 但是,这会返回一个编译时间错误: 我试过 但运行时错误是: 注意环境变量设置如下: $ b $你应该像你一样设置env变量: 然后重新启动您的ide,如果您正在使用或重新启动终端会话。 我试过了,这里是我的截图。一切按预期工作...... I'm trying to set a cron Scheduled annotation as follows: Next set the environment variable as: However, I get the runtime error: What can be going wrong? EDIT I have also tried: But this returns a compile time error: I have tried But the runtime error was: Note the environment variable is set as follows:
You should set env variable like you do: then restart your ide if you are using or restart your terminal session. I tried it and here is my screenshot. Everything works as expected... 这篇关于Cron表达式必须包含6个字段(在#{systemEnvironment ['db_cron']}“中找到1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
@Scheduled(cron =$ {db_cron})
/Users/snowch/repos/sales/Prospects/Snow/Plugwise/etl_service/src/main/groovy/com/ibm/etl/Application.groovy:52:预期的'$ db_cron'是一个类型的内联常量java.lang.String in @ org.springframework.scheduling.annotation.Scheduled
@ line 52,23。
@Scheduled(cron =$ {db_cron})
^
/Users/snowch/repos/sales/Prospects/Snow/Plugwise/etl_service/src/main/groovy/com/ibm/etl/Application.groovy:-1:属性'cron'应该有类型'java.lang.String' ;但在@ org.springframework.scheduling.annotation.Scheduled
@ line -1,column -1中找到类型'java.lang.Object'。
2错误
:compileGroovy失败
失败:生成失败,出现异常。
@Scheduled(cron =#{db_cron})
线程main中的异常groovy.lang.MissingMethodException:方法没有签名:static org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.setSystemPropertiesMode()适用于参数类型:(java .lang.Integer)值:[2]
可能的解决方案: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.j ava:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at com.ibm.etl.Application.main(Application.groovy:43)
snowch $ echo$ db_cron
0 19 21 * * *
export db_cron =0 19 21 * * *
@Scheduled(cron =$ {db_cron})
def void schedule() {b $ b ...
}
@Scheduled(cron = "#{systemEnvironment['db_cron']}")
def void schedule() {
}
export db_cron="0 19 21 * * *"
Cron expression must consist of 6 fields
(found 1 in "#{systemEnvironment['db_cron']}")
@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.
@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)
snowch$ echo "$db_cron"
0 19 21 * * *
export db_cron="0 19 21 * * *"
@Scheduled(cron = "${db_cron}")
def void schedule() {
...
}