When using Spring Websocket with Spring Boot, the latter provides a WebSocketMessagingAutoConfiguration which provides a default WebSocketMessageBrokerConfigurer which sets either the single task executor found in the context or the executor named "applicationTaskExecutor" for the inbound and outbound client channels:

https://github.com/spring-projects/spring-boot/blob/619b24a8105719094b4dabd10fd22cea0325c776/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java#L69-L80

https://github.com/spring-projects/spring-boot/blob/619b24a8105719094b4dabd10fd22cea0325c776/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/websocket/servlet/WebSocketMessagingAutoConfiguration.java#L94-L106

When trying to set a custom executor for my inbound and outbound channels in my custom WebSocketMessageBrokerConfigurer implementation, it doesn't have any effect. The issue seems to be, that in DelegatingWebSocketMessageBrokerConfiguration the list of configurers always (at least in my case), processes the default configurer provided by Spring Boot after my custom one, causing my executor configuration to be overridden with the default one.

https://github.com/spring-projects/spring-framework/blob/c2c6bb25c68c231e8eb250809442987512755d62/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java#L49-L54

Debugging shows the order: SpringBoot Default WebSocketMessageBrokerConfigurer is always overriding custom channel executor

https://github.com/spring-projects/spring-framework/blob/c2c6bb25c68c231e8eb250809442987512755d62/spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.java#L71-L83

Instead, the DelegatingWebSocketMessageBrokerConfiguration should probably always process the default implementation first and then any custom configurers, probably via looking at @Order annotations. Now I don't know if that is an issue which must be handled in Spring Boot or in Spring Framework, but I can raise the issue in the latter project if you feel like it should be handled there.

Comment From: philwebb

It looks to me like DelegatingWebSocketMessageBrokerConfiguration uses standard @Autowired constructors which will respect ordering. We probably need to add @Ordered to our bean, but I'm not sure if we can do that in a maintenance release.

Comment From: shmyer

DelegatingWebSocketMessageBrokerConfiguration is actually using setter injection instead of constructor injection, but I guess that what you said about ordering applies for setters, too?

Comment From: philwebb

We consider this a bug and we're going to add @Order(0), but it's a risky change so we'll do it in 3.4.x.

Comment From: shmyer

Thanks! In the meantime I found a workaround by excluding the WebSocketMessagingAutoConfiguration via spring.autoconfigure.exclude and introducing any configuration required from it in my custom WebSocketMessageBrokerConfigurer.

Comment From: jack5505

hello community can I work on this bugs

Comment From: philwebb

Thanks for the offer @jack5505, but I started on this yesterday and forgot to assign myself. The code change is easy, but I'm also trying to create a test.