@Scheduled不执行

发布时间 2023-05-06 14:21:46作者: 菊草叶与圆企鹅

配置正确不报错,仅不执行

思路一

在Bean上加上

@EnableScheduling

思路二

扫描配置文件applicationContext-extends.xml里,对项目包的配置放在最后面(原来放在第一位)

<context:component-scanbase-package="com.abc.xm">
<context:exclude-filtertype="annotation"expression="org.springframework.stereotype.Controller"/>
</context:component-scan>

方法报错

报错信息为:
Only no-arg methods may be annotated with @Scheduled

解决方法:
@Scheduled注解下的方法带有参数,把@Scheduled注解下的方法的参数去掉就可以了

参数报错

报错信息:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'insterIntoConsumption': For input string: "L"

原因:
项目中使用的springBoot较老,不支持L W C 这样的表达式,会报错

临时解决方法:
按照项目要求修改,如要求每个月最后一天执行:

@Scheduled(cron = "0 0 23 28-31 * ?")