Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何修复Spring Boot应用程序中WebSocket和Shedlock的兼容性_Java_Spring Boot_Websocket_Hazelcast_Shedlock - Fatal编程技术网

Java 如何修复Spring Boot应用程序中WebSocket和Shedlock的兼容性

Java 如何修复Spring Boot应用程序中WebSocket和Shedlock的兼容性,java,spring-boot,websocket,hazelcast,shedlock,Java,Spring Boot,Websocket,Hazelcast,Shedlock,我有一个springboot实时应用程序,它使用Websockets和SockJS。目前,我正在使用LoadBalancer和两个实例扩展我的应用程序。由于应用程序中几乎没有cron作业,我需要在两台服务器之间同步它,以便一次只运行一个任务。为此,我使用了shedlock spring和shedlock提供者hazelcast依赖项(我还在应用程序中使用hazelcast) 如果我将@EnableSchedulerLock(defaultLockAtMostFor=“PT1S”)注释添加到Mai

我有一个springboot实时应用程序,它使用Websockets和SockJS。目前,我正在使用LoadBalancer和两个实例扩展我的应用程序。由于应用程序中几乎没有cron作业,我需要在两台服务器之间同步它,以便一次只运行一个任务。为此,我使用了shedlock spring和shedlock提供者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
注释工作正常,因为我在单独的应用程序中对其进行了测试,但它似乎与WebSocket冲突,并覆盖了一些bean。我不熟悉WebSocket配置,因此如果有人知道此错误的原因以及如何修复,请提供帮助

下面是我的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");
    }
}

ShedlLock默认情况下围绕ThreadPoolTaskScheduler创建代理,SpringWebSocket似乎需要
ThreadPoolTaskScheduler
instance


您可以像这样将ShedLock切换到AOP代理模式
@EnableSchedulerLock(mode=proxy\u方法,defaultLockAtMostFor=“PT1S”)
请参阅中的更多信息。(顺便说一句,1秒锁Atmost因为时间很短,如果您不另外指定,所有锁将在1秒后释放)

谢谢@Lucas,您救了我一天!我在寻找如何修复Websocket而不是修复ShedLock)要修复Websocket,您需要修复Spring Websocket源代码。我会尝试向他们发送拉请求。春季GitHub发布OMG lucas。。。你救了我的公司