[英]spring-boot and shedlock - how to track down dependency conflicts?
[英]How to fix Websockets and Shedlock compatibility in Spring Boot application
我有一個將Websockets與SockJS一起使用的Spring Boot實時應用程序。 目前,我正在使用LoadBalancer和兩個實例擴展我的應用程序。 由於應用程序中的cron作業很少,因此我需要在兩台服務器之間同步它,以一次僅運行一個任務。 為此,我使用了shedlock-spring和shedlock-provider-hazelcast依賴關系(我也在應用程序中使用了Hazelcast)。
如果我將@EnableSchedulerLock(defaultLockAtMostFor = "PT1S")
添加到MainApplication.class
應用程序中,則由於以下錯誤而無法啟動注釋:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stompWebSocketHandlerMapping' defined in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception; nested exception is java.lang.IllegalStateException:
@Bean method AbstractMessageBrokerConfiguration.messageBrokerTaskScheduler called as a bean reference for type [org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler] but overridden by non-compatible bean instance of type [com.sun.proxy.$Proxy136].
Overriding bean of same name declared in: class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]
@SchedulerLock
注釋可以正常工作,因為我在單獨的應用程序中對其進行了測試,但是它似乎與Websockets沖突並覆蓋了某些bean。 我是Websockets配置的新手,所以如果有人知道此錯誤的原因以及如何解決此問題,請提供幫助。
這是我的Websocket配置,可以完美運行:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket")
.setAllowedOrigins("*")
.withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app")
.enableSimpleBroker("/notification");
}
}
ShedLock默認情況下會圍繞ThreadPoolTaskScheduler創建一個代理,並且看來Spring Websockets需要ThreadPoolTaskScheduler
實例。
您可以將ShedLock像這樣@EnableSchedulerLock(mode = PROXY_METHOD, defaultLockAtMostFor = "PT1S")
切換到AOP代理模式。請參閱文檔中的更多信息。 (作為一個附帶說明,1秒的lockAtMostFor時間非常短,如果未指定,則所有鎖定將在1秒后釋放)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.