Cron表达式必须包含6个字段(在#{systemEnvironment ['db_cron']}“中找到1) [英] Cron expression must consist of 6 fields (found 1 in "#{systemEnvironment['db_cron']}")

查看:2018
本文介绍了Cron表达式必须包含6个字段(在#{systemEnvironment ['db_cron']}“中找到1)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  @Scheduled(cron =#{systemEnvironment [ 'db_cron']})
def void schedule(){

}

接下来将环境变量设置为:

  export db_cron =0 19 21 * * *

但是,我得到运行时错误:

  Cron表达式必须包含6个字段
(在#{systemEnvironment ['db_cron']}中找到1)

有什么可能会出错?






编辑

我也试过: @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 * * *

$ b $你应该像你一样设置env变量:

  export db_cron =0 19 21 * * *

然后重新启动您的ide,如果您正在使用或重新启动终端会话。

  @Scheduled(cron =$ {db_cron})
def void schedule() {b $ b ...
}

我试过了,这里是我的截图。一切按预期工作......


I'm trying to set a cron Scheduled annotation as follows:

@Scheduled(cron = "#{systemEnvironment['db_cron']}")
def void schedule() {

}

Next set the environment variable as:

export db_cron="0 19 21 * * *"

However, I get the runtime error:

Cron expression must consist of 6 fields 
  (found 1 in "#{systemEnvironment['db_cron']}")

What can be going wrong?


EDIT

I have also tried: @Scheduled(cron = "${db_cron}")

But this returns a compile time error:

/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.

I have tried @Scheduled(cron = "#{db_cron}")

But the runtime error was:

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)

Note the environment variable is set as follows:

snowch$ echo "$db_cron"
0 19 21 * * *

解决方案

You should set env variable like you do:

export db_cron="0 19 21 * * *"

then restart your ide if you are using or restart your terminal session.

@Scheduled(cron = "${db_cron}")
def void schedule() {
   ...
}

I tried it and here is my screenshot. Everything works as expected...

这篇关于Cron表达式必须包含6个字段(在#{systemEnvironment ['db_cron']}“中找到1)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆