No task executor bean found for async processing
No task executor bean found for async processing: no bean of type TaskExecutor and no bean named taskExecutor either
检查日志的时候发现一个打印,这么一看貌似想个错误一样,但是级别是info? 然后去找到上下文一看,原来是springboot提供的异步调用@Async产生的。
具体的说明可以参考:
部分参考:
原来我的代码中没有指定executor,所以springboot找来找去找到了默认的,然后打了一串东西。
添加代码:
@SpringBootApplication @ServletComponentScan @EnableCaching @EnableAsync public class ApiApplication { public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } // 这里是新添加的线程池代码 @Bean(name = "threadPoolTaskExecutor") public Executor threadPoolTaskExecutor() { // 使用 google的Guava包 ThreadFactory namedThreadFactory = new ThreadFactoryBuilder() .setNameFormat("my-pool-%d").build(); // 构造一个线程池 return new ThreadPoolExecutor( 5, 200, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), namedThreadFactory, new ThreadPoolExecutor.AbortPolicy()); } }
需要的pom:
<dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>18.0</version> </dependency>
然后在异步的地方:
/** * 如果没有特别指定,默认使用SimpleAsyncTaskExecutor,执行异步方法. */ @Async("threadPoolTaskExecutor") public void xcx(String uid, String orderId) { .......
另外关于配置AsyncConfigurer请大家自行修改了,我这里没有使用了。
over。