Cron expression must consist of 6 fields (found 7 in "0 * * * * ? *")

    在SpringBoot上写一个定时器,要求,一个小时执行一次,BUT。。。

Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'Timer': Cron expression must consist of 6 fields (found 7 in "0 * * * * ? *")
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:564)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    写上去之后,直接给启动失败了,额额额,看报错的意思是,只能是6位的,而我写了7位,查了资料后,有网友说,最后一位表示的年,1099~2099年,可以省略不写,果断把最后一个星号“ * ”,去掉后,就可以啦,嘿嘿嘿,又涨姿势啦!
posted @ 2022-01-27 18:36  zhangdaopin  阅读(1940)  评论(0编辑  收藏  举报