2929
3030import com .fasterxml .jackson .databind .ObjectMapper ;
3131import org .apache .tomcat .websocket .WsWebSocketContainer ;
32+ import org .assertj .core .api .InstanceOfAssertFactories ;
3233import org .junit .jupiter .api .AfterEach ;
3334import org .junit .jupiter .api .BeforeEach ;
3435import org .junit .jupiter .api .Test ;
4041import org .springframework .boot .autoconfigure .task .TaskExecutionAutoConfiguration ;
4142import org .springframework .boot .autoconfigure .web .servlet .DispatcherServletAutoConfiguration ;
4243import org .springframework .boot .autoconfigure .web .servlet .ServletWebServerFactoryAutoConfiguration ;
44+ import org .springframework .boot .autoconfigure .websocket .servlet .WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration ;
4345import org .springframework .boot .context .properties .EnableConfigurationProperties ;
4446import org .springframework .boot .test .util .TestPropertyValues ;
4547import org .springframework .boot .web .embedded .tomcat .TomcatServletWebServerFactory ;
4648import org .springframework .boot .web .servlet .context .AnnotationConfigServletWebServerApplicationContext ;
4749import org .springframework .context .annotation .Bean ;
4850import org .springframework .context .annotation .Configuration ;
51+ import org .springframework .core .Ordered ;
52+ import org .springframework .core .annotation .Order ;
4953import org .springframework .core .task .AsyncTaskExecutor ;
5054import org .springframework .core .task .SimpleAsyncTaskExecutor ;
5155import org .springframework .core .task .TaskExecutor ;
6266import org .springframework .messaging .simp .stomp .StompSessionHandler ;
6367import org .springframework .messaging .simp .stomp .StompSessionHandlerAdapter ;
6468import org .springframework .security .util .FieldUtils ;
69+ import org .springframework .stereotype .Component ;
6570import org .springframework .stereotype .Controller ;
6671import org .springframework .web .client .RestTemplate ;
6772import org .springframework .web .socket .client .standard .StandardWebSocketClient ;
@@ -162,6 +167,26 @@ void predefinedThreadExecutorIsSelectedForOutboundChannel() throws Throwable {
162167 assertThat (executor ).isEqualTo (expectedExecutor );
163168 }
164169
170+ @ Test
171+ void webSocketMessageBrokerConfigurerOrdering () throws Throwable {
172+ TestPropertyValues .of ("server.port:0" , "spring.jackson.serialization.indent-output:true" ).applyTo (this .context );
173+ this .context .register (WebSocketMessagingConfiguration .class , CustomLowWebSocketMessageBrokerConfigurer .class ,
174+ CustomHighWebSocketMessageBrokerConfigurer .class );
175+ this .context .refresh ();
176+ DelegatingWebSocketMessageBrokerConfiguration delegatingConfiguration = this .context
177+ .getBean (DelegatingWebSocketMessageBrokerConfiguration .class );
178+ CustomHighWebSocketMessageBrokerConfigurer high = this .context
179+ .getBean (CustomHighWebSocketMessageBrokerConfigurer .class );
180+ WebSocketMessageConverterConfiguration autoConfiguration = this .context
181+ .getBean (WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration .class );
182+ WebSocketMessagingConfiguration configuration = this .context .getBean (WebSocketMessagingConfiguration .class );
183+ CustomLowWebSocketMessageBrokerConfigurer low = this .context
184+ .getBean (CustomLowWebSocketMessageBrokerConfigurer .class );
185+ assertThat (delegatingConfiguration ).extracting ("configurers" )
186+ .asInstanceOf (InstanceOfAssertFactories .LIST )
187+ .containsExactly (high , autoConfiguration , configuration , low );
188+ }
189+
165190 private List <MessageConverter > getCustomizedConverters () {
166191 List <MessageConverter > customizedConverters = new ArrayList <>();
167192 WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration configuration = new WebSocketMessagingAutoConfiguration .WebSocketMessageConverterConfiguration (
@@ -246,6 +271,7 @@ static class WebSocketMessagingConfiguration implements WebSocketMessageBrokerCo
246271
247272 @ Override
248273 public void registerStompEndpoints (StompEndpointRegistry registry ) {
274+
249275 registry .addEndpoint ("/messaging" ).withSockJS ();
250276 }
251277
@@ -271,6 +297,18 @@ TomcatWebSocketServletWebServerCustomizer tomcatCustomizer() {
271297
272298 }
273299
300+ @ Component
301+ @ Order (Ordered .HIGHEST_PRECEDENCE )
302+ static class CustomHighWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
303+
304+ }
305+
306+ @ Component
307+ @ Order (Ordered .LOWEST_PRECEDENCE )
308+ static class CustomLowWebSocketMessageBrokerConfigurer implements WebSocketMessageBrokerConfigurer {
309+
310+ }
311+
274312 @ Controller
275313 static class MessagingController {
276314
0 commit comments