博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
No qualifying bean of type 'org.springframework.scheduling.TaskScheduler' available
阅读量:5272 次
发布时间:2019-06-14

本文共 7891 字,大约阅读时间需要 26 分钟。

2019-07-22 17:59:30,966 [DEBUG] [localhost-startStop-1] [ScheduledAnnotationBeanPostProcessor.java : 245] Could not find default TaskScheduler beanorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.springframework.scheduling.TaskScheduler' available    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:996)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.resolveSchedulerBean(ScheduledAnnotationBeanPostProcessor.java:286)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.finishRegistration(ScheduledAnnotationBeanPostProcessor.java:227)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:204)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:98)    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)    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.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)    at java.util.concurrent.FutureTask.run(FutureTask.java:266)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    at java.lang.Thread.run(Thread.java:748)2019-07-22 17:59:30,968 [DEBUG] [localhost-startStop-1] [ScheduledAnnotationBeanPostProcessor.java : 266] Could not find default ScheduledExecutorService beanorg.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'java.util.concurrent.ScheduledExecutorService' available    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:996)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.resolveSchedulerBean(ScheduledAnnotationBeanPostProcessor.java:286)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.finishRegistration(ScheduledAnnotationBeanPostProcessor.java:248)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:204)    at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.onApplicationEvent(ScheduledAnnotationBeanPostProcessor.java:98)    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)    at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:883)    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.finishRefresh(EmbeddedWebApplicationContext.java:144)    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546)    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.web.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:154)    at org.springframework.boot.web.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:134)    at org.springframework.boot.web.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:87)    at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5423)    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)    at java.util.concurrent.FutureTask.run(FutureTask.java:266)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    at java.lang.Thread.run(Thread.java:748)

晕啊,很明显这是定时任务的异常啊。可是定时任务明明能够正常运行啊,怎么回事?

尝试着删掉了所有的定时任务配置,果然异常消失了。但是只要启用任何一个定时任务,异常都会再次出现。这可真可怕。作为一个强迫症患者,不能放任这样的异常存在,于是仔细的查找了半天,却依旧没有结果。最后只好放大招,读spring的源码啦,这一读,可好,差点没把我郁闷死。

为什么郁闷呢? 不知道读这篇文章的朋友们有没有细心的,有没有注意这两个异常有一个非常特别的地方。什么地方呢? 这两个异常的级别,不是ERROR 也不是 WARNING

 居然是DEBUG

原来,Spring的定时任务调度器会尝试获取一个注册过的 task scheduler来做任务调度,它会尝试通过BeanFactory.getBean的方法来获取一个注册过的scheduler bean,获取的步骤如下:

1.尝试从配置中找到一个TaskScheduler Bean

2.寻找ScheduledExecutorService Bean

3.使用默认的scheduler

前两步,如果找不到的话,就会以debug的方式抛出异常,分别是:

logger.debug("Could not find default TaskScheduler bean", ex);

logger.debug("Could not find default ScheduledExecutorService bean", ex);

所以,日志中打印出来的两个异常,根本不是什么错误信息,也不会影响定时器的使用,只不过是spring的自己打印的一些信息罢了,不过没搞明白,为什么非要用异常的方式打出来,估计是为了看这清晰点吧。也或者,这里面有一些重要的信息需要提示开发者。具体是什么原因,只能有机会进一步再去了解了。

转载于:https://www.cnblogs.com/qingmuchuanqi48/p/11227605.html

你可能感兴趣的文章
[转]ceph网络通信模块_以monitor模块为例
查看>>
HDOJ 1754 I Hate It(线段树基本操作)
查看>>
latex tree
查看>>
安装NVIDIA驱动时禁用自带nouveau驱动
查看>>
HDU-1255 覆盖的面积 (扫描线)
查看>>
css3学习01
查看>>
【USACO】 奶牛会展
查看>>
继承和多态
查看>>
Dijkstra+计算几何 POJ 2502 Subway
查看>>
修复IE不能执行JS的方法
查看>>
程序员究竟该如何提高效率zt
查看>>
希尔排序法(缩小增量法)
查看>>
PHP编程基础学习(一)——数据类型
查看>>
MongoDB-JAVA-Driver 3.2版本常用代码全整理(2) - 查询
查看>>
NPOI处理Word文本中上下角标
查看>>
Android笔记 Handler
查看>>
如何阅读大型前端开源项目的源码(转)
查看>>
java.util.Arrays类详解
查看>>
idea搭建tocmat
查看>>
NYOJ-626-intersection set(二分查找)
查看>>