spring异步执行报异常No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available

最近观察项目运行日志的时候突然发现了一个异常,

[2018-04-03 10:49:07] 100.0.1.246 http-nio-8080-exec-9 DEBUG org.springframework.scheduling.annotation.AnnotationAsyncExecutionInterceptor———— Could not find default TaskExecutor bean
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.springframework.core.task.TaskExecutor‘ available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:353)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:340)
    at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.getDefaultExecutor(AsyncExecutionAspectSupport.java:228)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor.getDefaultExecutor(AsyncExecutionInterceptor.java:156)
    at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.determineAsyncExecutor(AsyncExecutionAspectSupport.java:166)
    at org.springframework.aop.interceptor.AsyncExecutionInterceptor.invoke(AsyncExecutionInterceptor.java:105)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
    at com.sun.proxy.$Proxy103.saveAndSendMQ(Unknown Source)
    at com.sinoway.cisp.aop.ReportAspect.saveLoanAndSendMQ(ReportAspect.java:78)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:629)
    at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:611)
    at org.springframework.aop.aspectj.AspectJAfterReturningAdvice.afterReturning(AspectJAfterReturningAdvice.java:65)
    at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:53)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:282)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)

仔细看了一下,异常属于DEBUG级别,并不影响系统运行,但是还是比较碍眼,查了好久,找到一个解决办法

import java.util.concurrent.Executor;

import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Configuration
@ComponentScan("切面所在的包名")@EnableAsync //开启异步任务支持   如果Application已经开启,则这个可以省略
public class TaskExecutorConfig implements AsyncConfigurer {
    // 此配置可以解决Could not find default TaskExecutor bean的debug异常
    @Override
    public Executor getAsyncExecutor() {// 实现AsyncConfigurer接口并重写getAsyncExecutor方法,并返回一个ThreadPoolTaskExecutor,这样我们就获得了一个基于线程池TaskExecutor
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(10);
        taskExecutor.setMaxPoolSize(80);
        taskExecutor.setQueueCapacity(100);
        taskExecutor.initialize();
        return taskExecutor;
    }

    @Override
    public AsyncUncaughtExceptionHandler getAsyncUncaughtExceptionHandler() {
        return null;
    }
}

具体原因未知,正在查找。特此记录一下有备无患

spring异步执行报异常No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available

原文地址:https://www.cnblogs.com/java-spring/p/8707789.html

时间: 2024-10-24 15:27:41

spring异步执行报异常No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available的相关文章

今天在搭建spring+reids框架时遇到No qualifying bean of type [org.springframework.data.redis.core.RedisTemplate]

今天在测试RedisTemplate时,用spring无法注入RedisTemplate,junit测试报错. Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.redis.core.RedisTemplate] found for dependency: expected at least

spring cloud gateway网关启动报错:No qualifying bean of type 'org.springframework.web.reactive.DispatcherHandler'

网关配置好后启动报错如下: org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'servletEndpoint

Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined

1. Overview In this article, we are discussing the Springorg.springframework.beans.factory.NoSuchBeanDefinitionException – this is a common exception thrown by the BeanFactory when trying to resolve a bean that simply isn’t defined in the Spring Cont

Spring4.14 事务异常 NoUniqueBeanDefinitionException: No qualifying bean of type [....PlatformTransactionManager]

环境为Spring + Spring mvc + mybatis:其中Spring版本为4.1.4 spring配置文件: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instanc

spring注入时报错::No qualifying bean of type &#39;xxx.xxMapper&#39;

做一个小项目,因为有 baseService,所以偷懒就没有写单独的每个xxService接口,直接写的xxServiceImpl,结果在service实现类中注入Mapper的时候,用的 @Autowired, 结果,junit一启动,就报错误:Java.lang.illegalStateException:Failed to load ApplicationContext 具体是在 创建bean的时候报:No qualifying bean of type 'xxx.xxMapper' ab

spring Boot异步操作报错误: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type &#39;com.self.spring.springboot.Jeep&#39; available

我也是最近开始学习Spring Boot,在执行异步操作的时候总是汇报如下的错误: Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.self.spring.springboot.Jeep' available at org.springframework.beans.factory.sup

springboot 报错 org.springframework.beans.factory.NoSuchBeanDefinitionException:No qualifying bean of type &#39;com.example.service.HrService&#39; available: 有没有大佬出个主意,我找了一天,刚入门springboot

话不多说先上图,这是启动类的配置,这里配置了@ComponentScan("我的mapper的接口") 接下来是我的项目结构截图 然后是service 的截图,我在这里加了注解@Service 最后我在测试类里面 的截图 最后附上我的maven的pom 我开始怀疑是这个配置的有问题了 <?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.a

No qualifying bean of type报错问题处理

org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [cn.appsys.service.DevUserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annota

添加事务后 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available

今天遇到了一个奇怪的问题   在没添加事务之前  所有的代码都是好的 , 当我添加了事务之后, 代码报错 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type available ApplicationContext: <!-- 配置事务 --> <bean id="transactionManager" class="org.s