From 9f8a50b230919f944f038dd5a78ba31e294ac956 Mon Sep 17 00:00:00 2001 From: CodeInDreams Date: Thu, 30 Jun 2022 17:52:51 +0800 Subject: [PATCH] Fix issue autowiring channelExecutors and taskScheduler in spring messaging & websocket --- .../config/AbstractMessageBrokerConfiguration.java | 14 +++++++++----- ...WebSocketMessageBrokerConfigurationSupport.java | 7 +++++-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java index 7c5cfed55021..1c97c028ed22 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java @@ -24,6 +24,7 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.BeanInitializationException; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.annotation.Bean; @@ -149,7 +150,8 @@ public ApplicationContext getApplicationContext() { @Bean - public AbstractSubscribableChannel clientInboundChannel(TaskExecutor clientInboundChannelExecutor) { + public AbstractSubscribableChannel clientInboundChannel( + @Qualifier("clientInboundChannelExecutor") TaskExecutor clientInboundChannelExecutor) { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientInboundChannelRegistration(); @@ -185,7 +187,8 @@ protected void configureClientInboundChannel(ChannelRegistration registration) { } @Bean - public AbstractSubscribableChannel clientOutboundChannel(TaskExecutor clientOutboundChannelExecutor) { + public AbstractSubscribableChannel clientOutboundChannel( + @Qualifier("clientOutboundChannelExecutor") TaskExecutor clientOutboundChannelExecutor) { ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor); channel.setLogger(SimpLogging.forLog(channel.getLogger())); ChannelRegistration reg = getClientOutboundChannelRegistration(); @@ -221,8 +224,9 @@ protected void configureClientOutboundChannel(ChannelRegistration registration) } @Bean - public AbstractSubscribableChannel brokerChannel(AbstractSubscribableChannel clientInboundChannel, - AbstractSubscribableChannel clientOutboundChannel, TaskExecutor brokerChannelExecutor) { + public AbstractSubscribableChannel brokerChannel( + AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, + @Qualifier("brokerChannelExecutor") TaskExecutor brokerChannelExecutor) { MessageBrokerRegistry registry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel); ChannelRegistration registration = registry.getBrokerChannelRegistration(); @@ -411,7 +415,7 @@ public UserDestinationMessageHandler userDestinationMessageHandler( public MessageHandler userRegistryMessageHandler( AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, SimpUserRegistry userRegistry, SimpMessagingTemplate brokerMessagingTemplate, - TaskScheduler messageBrokerTaskScheduler) { + @Qualifier("messageBrokerTaskScheduler") TaskScheduler messageBrokerTaskScheduler) { MessageBrokerRegistry brokerRegistry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel); if (brokerRegistry.getUserRegistryBroadcast() == null) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java index e42195502b5e..74739ecbe6fb 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupport.java @@ -16,6 +16,7 @@ package org.springframework.web.socket.config.annotation; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.config.CustomScopeConfigurer; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; @@ -129,8 +130,10 @@ public static CustomScopeConfigurer webSocketScopeConfigurer() { @Bean public WebSocketMessageBrokerStats webSocketMessageBrokerStats( @Nullable AbstractBrokerMessageHandler stompBrokerRelayMessageHandler, - WebSocketHandler subProtocolWebSocketHandler, TaskExecutor clientInboundChannelExecutor, - TaskExecutor clientOutboundChannelExecutor, TaskScheduler messageBrokerTaskScheduler) { + WebSocketHandler subProtocolWebSocketHandler, + @Qualifier("clientInboundChannelExecutor") TaskExecutor clientInboundChannelExecutor, + @Qualifier("clientOutboundChannelExecutor") TaskExecutor clientOutboundChannelExecutor, + @Qualifier("messageBrokerTaskScheduler") TaskScheduler messageBrokerTaskScheduler) { WebSocketMessageBrokerStats stats = new WebSocketMessageBrokerStats(); stats.setSubProtocolWebSocketHandler((SubProtocolWebSocketHandler) subProtocolWebSocketHandler);