Only no-arg methods may be annotated with @Scheduled 的解决方法
问题描述
今天在写爬虫代码时,需要个定时抓取任务,测试时SpringBoot项目启动时报错,记录一下问题
Only no-arg methods may be annotated with @Scheduled
控制台输出错误日志:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'commentSubmit': Only no-arg methods may be annotated with @Scheduledat org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:518)at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null$1(ScheduledAnnotationBeanPostProcessor.java:380)at java.lang.Iterable.forEach(Iterable.java:75)at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$2(ScheduledAnnotationBeanPostProcessor.java:380)at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:379)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620)... 15 more
原因分析:
报错的大致意思是使用@Scheduled
注解的方法不能带参数,看了下自己的代码,确实存在这个问题,那就很好解决了
解决方案:
1、可以选择不适用SpringBoot自带Scheduler,使用xml配置等其他方式实现定时任务
2、如果确定使用Scheduler,那只有根据自己的业务需求改造方法了
创作不易,关注
Only no-arg methods may be annotated with @Scheduled 的解决方法相关推荐
- Only no-arg methods may be annotated with @Scheduled
如果出现这个错误:Only no-arg methods may be annotated with @Scheduled说明你的方法不能有参数.
- Only no-arg methods may be annotated with @Scheduled报错
问题背景 今天在弄一个手工爬虫框架的时候,由于有个功能如下: 在列表界面点击抓取,进行手工抓取 后台根据application.yml设置的定时任务自动触发抓取任务 /*** 广东省政府采购中心*/@ ...
- AndroidStudio EventBus报错解决方法its super classes have no public methods with the @Subscribe
AndroidStudio EventBus报错解决方法its super classes have no public methods with the @Subscribe 参考文章: (1)An ...
- vue组件获取props_vue中子组件的methods中获取到props中的值方法
父子组件通信 这个官网很清楚,也很简单,父组件中使用v-bind绑定传送,子组件使用props接收即可 例如: 父组件中 数据统计 统计: 销售数量 {{number}} 销售金额 {{amount} ...
- latex中使用bibtex显示paragraph ended before \mule@arg was complete 的解决方法
我当时是因为作者人名里有个字母系统无法识别但在bll文件里录入了,导致一直报错并且无法再次修改. 这种情况虽然报错,但是一般都能生成pdf文件,对照pdf文件看哪里开始不显示的,调出bll文件,直接在 ...
- QMetaMethod::invoke: Unable to invoke methods with return values in queued connections
报错信息为: QMetaMethod::invoke: Unable to invoke methods with return values in queued connections 解决方法是: ...
- 注解 @Scheduled
2019独角兽企业重金招聘Python工程师标准>>> 我们跑定时的时候,代码的结构大致是这个样子的. @Scheduled(cron="0 0 4 * * ?" ...
- spring源码分析之定时任务Scheduled注解
1. @Scheduled 可以将一个方法标识为可定时执行的.但必须指明cron(),fixedDelay(),或者fixedRate()属性. 注解的方法必须是无输入参数并返回空类型void的. @ ...
- SpringBoot实现定时任务
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Co ...
- Spring@Schedule定时任务源码解析
本文以springboot中cron表达式配置的定时任务为例子. 在springboot中的启动类中添加@EnableScheduling注解,在beanFactory中添加ScheduledAnno ...
最新文章
- .NET环境下有关打印页面设置、打印机设置、打印预览对话框的实现
- python无限循环条件循环_python 语句,条件,循环
- 【数据平台】pandas按条件去重
- pmp思维导图 第六版_《每天一小时,两月过PMP》备考指南(附计划表)
- android与mysql的交互,与Android中的外部SQLite数据库进行交互.
- gethours_日期getHours()方法以及JavaScript中的示例
- R 多变量数据预处理_超长文详解:C语言预处理命令
- Entity Framework使用Sqlite时的一些配置
- 大数据分析推动业务增长的方法有哪些
- ROW_NUMBER() OVER的用法
- NEU1217之神风堂最少人数 自己在精度上吃了苦头
- 汉王手写板linux驱动下载,汉王笔手写板驱动程序
- ZEMAX光学设计实践
- 再说setlocale——关于区域名称
- 蒟蒻的第一篇博客(洛谷P1113)
- 关于微信jsapi 支付签名验证失败
- Python实现网页自动化-浏览器查找元素(二)
- Pytorch3D_上手学习3D的AI模型
- 新品发布 | P600准行业无人机研发平台,室外视觉识别跟踪、激光雷达避障、多机组网!
- 第二次结对编程——电梯调度算法UI贾伟王伟东
热门文章