【发布时间】:2019-10-07 12:32:59
【问题描述】:
我有一个使用 @Async-Tasks 的 Spring Boot 2.1.8 应用程序。所有@Async-Tasks 过去都由一个名为applicationTaskExecutor 的自动配置的ThreadPoolTaskExecutor-bean 执行。
我改变了什么?
在类路径中使用 spring-boot-starter-websocket 和 @EnableWebSocketMessageBroker 配置时,applicationTaskExecutor-bean 消失了,取而代之的是四个名称为
-
clientInboundChannelExecutor, -
clientOutboundChannelExecutor, -
brokerChannelExecutor, - 和
messageBrokerTaskScheduler。
Spring 将日志记录到控制台:AnnotationAsyncExecutionInterceptor : More than one TaskExecutor bean found within the context, and none is named 'taskExecutor'. Mark one of them as primary or name it 'taskExecutor' (possibly as an alias) in order to use it for async processing: [clientInboundChannelExecutor, clientOutboundChannelExecutor, brokerChannelExecutor, messageBrokerTaskScheduler]
@Async-tasks 现在由SimpleAsyncTaskExecutor 执行。
问题
为什么所有的豆子都不能共存?为什么配置spring-websockets时Spring不会创建applicationTaskExecutor-bean?
【问题讨论】:
-
只有在没有其他
TaskExecutor可用时才会创建applicationTaskExecutor。如果有,则不会创建。见github.com/spring-projects/spring-boot/blob/master/…。
标签: spring-boot