HoneyMoose
  • 首页
  • Java
  • Jersey
  • Jira
  • Confluence
  • U.S.
    • USRealEstate
    • USVisaTrack
    • H1B
  • 项目和网站
    • CWIKI.US
    • OSSEZ 社区
    • WIKI.OSSEZ.COM
    • BUG.OSSEZ.COM
    • RSS.OSSEZ.COM
BLOG.OSSEZ.COM
A responsive blog theme focused om user reading experience
  1. Home
  2. Computer Science
  3. Spring
  4. This article

Spring Could not find unique TaskExecutor bean 错误

2020年10月28日 1017Browse 0Like 0Comments

这个错误其实是 debug 级别的错误,是不影响运行的。

错误栈为:

020-10-26 15:27:57.726 DEBUG 12844 --- [nio-8080-exec-1] .s.a.AnnotationAsyncExecutionInterceptor : Could not find unique TaskExecutor bean

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.springframework.core.task.TaskExecutor' available: expected single matching bean but found 2: applicationTaskExecutor,taskScheduler
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveNamedBean(DefaultListableBeanFactory.java:1200)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveBean(DefaultListableBeanFactory.java:420)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:350)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:343)
	at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.getDefaultExecutor(AsyncExecutionAspectSupport.java:233)
	at org.springframework.aop.interceptor.AsyncExecutionInterceptor.getDefaultExecutor(AsyncExecutionInterceptor.java:157)
	at org.springframework.aop.interceptor.AsyncExecutionAspectSupport.lambda$configure$2(AsyncExecutionAspectSupport.java:119)

原因和解决

简单来说就是在你的 @Configuration 中必须要实现一个 AsyncConfigurer 来为 @Async 指定一个 TaskExecutor 执行的方法。

package com.insight.sco.service.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.Executor;

/**
 * AsyncConfigurer for Spring
 *
 * @author YuCheng Hu
 */
@Configuration
@Component
@EnableAsync
public class TaskExecutorConfig implements AsyncConfigurer{

    /**
     * Override Config
     *
     * @return
     */
    @Override
    public Executor getAsyncExecutor(){
        ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
        taskExecutor.setCorePoolSize(10);
        taskExecutor.setMaxPoolSize(80);
        taskExecutor.setQueueCapacity(100);
        taskExecutor.initialize();
        return taskExecutor;
    }
}

可以将上面的方法拷贝放到你 Spring 的项目中,这样你的 Spring 项目就可以告诉应用的上下文使用哪一个异步方法。

 

Spring-Could-01
 
https://www.ossez.com/t/spring-could-not-find-unique-taskexecutor-bean/614

 

Tags: None
Last updated:2020年10月28日

Kratos

stay absorbed stay excellent

Like
< Previous
Next >

Comments

Cancel reply

Newest Hotspots Random
Newest Hotspots Random
ChatGPT 的 API 调用可不太便宜 来看一个 ChatGPT 有关程序员的笑话 IntelliJ IDEA 的 Code Coverage 测试 Okhttp 如何构建一个 Get 的 URL SpringBoot 使用 @ConfigurationProperties 异常 Not registered via @EnableConfigurationProperties Jackson 的 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
说说这 48 小时核酸检测的时间FAA 真的应该换换系统了Java 8 使用 Stream 把 List 转换为 mapPowerShell 中运行 maven 参数无法识别1月14号的 UA857Jackson 的 DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES
微软 WSL 重装操作系统 Confluence 6 附件存储配置 Confluence 6 通过 SSL 或 HTTPS 运行 - 备注和问题解决 Confluence 6 关于 Decorators @ComponentScan 无参数 美国 Foreclosure(法拍房)的启动流程
Categories
  • Algorithm(算法)
  • AMQP
  • Angular
  • CI
  • Compile And CI
  • Computer Science
  • Confluence
  • DataBase
  • Gradle
  • H1B
  • Hibernate
  • IDE
  • Java
  • Jersey
  • Jira
  • MariaDB
  • PrestaShop
  • Spring
  • Spring Batch
  • U.S.
  • USRealEstate
  • USVisaTrack
  • 我的小厨

COPYRIGHT © 2020 HoneyMoose. ALL RIGHTS RESERVED.

THEME CWIKIUS.CN MADE BY VTROIS