In upgrading a Spring Boot 2 application to Spring Boot 3 (Spring 5 to Spring 6) it fails to start due to WebSocket configuration.
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
// ---------------------------------
// This works in Spring Boot 2 and 3
// ---------------------------------
config.enableSimpleBroker("/topic");
// -------------------------------------------------------
// This works in Spring Boot 2, but fails in Spring Boot 3
// -------------------------------------------------------
config.enableSimpleBroker("/topic")
.setHeartbeatValue(new long[] { 10000, 10000 })
.setTaskScheduler(new DefaultManagedTaskScheduler());
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/gs-guide-websocket");
}
}
Trying to set the heartbeat and task scheduler fails with the following information in Spring Boot 3 (Spring 6).
INFO 19002 --- [demo] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port 8080 (http) with context path '/'
INFO 19002 --- [demo] [ main] o.s.m.s.b.SimpleBrokerMessageHandler : Starting...
INFO 19002 --- [demo] [ main] o.s.m.s.b.SimpleBrokerMessageHandler : BrokerAvailabilityEvent[available=true, SimpleBrokerMessageHandler [org.springframework.messaging.simp.broker.DefaultSubscriptionRegistry@49a6f486]]
WARN 19002 --- [demo] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'simpleBrokerMessageHandler'
INFO 19002 --- [demo] [ main] .s.b.a.l.ConditionEvaluationReportLogger :
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
ERROR 19002 --- [demo] [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.context.ApplicationContextException: Failed to start bean 'simpleBrokerMessageHandler'
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288) ~[spring-context-6.1.11.jar:6.1.11]
...
Caused by: java.lang.IllegalStateException: No ScheduledExecutor is configured
...
Any ideas how to fix this? Specifically how to set heartbeat values for WebSockets in Spring Boot 3 (Spring 6)?