springboot 自带定时任务 报错expected single matching bean but found 2: taskExecutor,taskScheduler

在使用Springboot自带的@Scheduled定时任务时遇到NoUniqueBeanDefinitionException,错误信息提示存在两个TaskExecutor。解决方案是在配置类中实现SchedulingConfigurer和AsyncConfigurer接口,分别定制定时任务和异步任务的线程池,确保bean的唯一性。通过添加ExecutorConfig类并设置不同的线程池属性,问题得到解决。
摘要由CSDN通过智能技术生成

我遇到springboot自带的异步定时任务时报错,但不影响运行,报错信息如下:

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: taskExecutor,taskScheduler

解决方法是加下面的类对异步任务重新定义。我在网上找了一天也没解决,后来遇到https://www.cnblogs.com/gaomanito/p/11120164.html加入后就解决了。

import lombok.extern.slf4j.Slf4j;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.AsyncConfigurer;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
impo

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值