-
Notifications
You must be signed in to change notification settings - Fork 38.9k
Description
Affects: Spring Boot > 2.6.0, Spring Framework 5.3.10
Hello everyone,
right before the weekend I updated our microservices to Spring Boot 2.6.0. Some of them using websockets for real-time synchronization with the UI. A while ago we set them up using the suggested configuration as seen in:
Now, without any changes to our code, our websocket configuration contains a circular dependency which can be fully removed when removing the TaskScheduler, which of course isn't the solution, but helps to determine the circular dependency. In my opinion the suggested configuration should not contain a circular dependency when it is not recommended to use them.
One should probably update the documentation to fix this issue.
So far I have found two ways to fix this problem. First being a lazy initialization of the TaskScheduler bean:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
private TaskScheduler messageBrokerTaskScheduler;
// Note the @Lazy
@Autowired
public void setMessageBrokerTaskScheduler(@Lazy TaskScheduler taskScheduler) {
this.messageBrokerTaskScheduler = taskScheduler;
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/")
.setHeartbeatValue(new long[] {10000, 20000})
.setTaskScheduler(this.messageBrokerTaskScheduler);
// ...
}
}This does not work. The second one is overloading the method `configureMessageBroker`:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
public void configureMessageBroker(MessageBrokerRegistry registry, TaskScheduler messageBrokerTaskScheduler) {
registry.enableSimpleBroker("/queue/", "/topic/")
.setHeartbeatValue(new long[] {10000, 20000})
.setTaskScheduler(messageBrokerTaskScheduler);
// ...
}
}Should the documentation be updated or are there any downsides of using the suggested solutions?