小编典典

Spring Boot Websocket 1.2.1.RELEASE- bean'subProtocolWebSocketHandler'中的IllegalArgumentException:没有处理程序

spring-boot

所以我想将我的项目从Spring Boot 1.1.9.RELEASE升级到1.2.1.RELEASE。

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <version>${spring.boot.version}</version>
    </dependency>

但是,在启动时,我获得了:

Exception in thread "Thread-0" org.springframework.context.ApplicationContextException: Failed to start bean 'subProtocolWebSocketHandler'; nested exception is java.lang.IllegalArgumentException: No handlers
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:176)
        at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:51)
        at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:346)
        at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:149)
        at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:112)
        at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:770)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:483)
        at org.springframework.context.annotation.AnnotationConfigApplicationContext.<init>(AnnotationConfigApplicationContext.java:95)
        at com.springagain.Application.run(Application.java:17)
Caused by: java.lang.IllegalArgumentException: No handlers
        at org.springframework.util.Assert.isTrue(Assert.java:65)
        at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:234)
        at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173)
        ... 8 more

这是我的WebSocket配置的外观

@Configuration
@EnableWebSocketMessageBroker
public class WebsocketConfiguration extends
        AbstractWebSocketMessageBrokerConfigurer {

    @Override
    public void configureMessageBroker(MessageBrokerRegistry registry) {
        registry.enableStompBrokerRelay("/queue/", "/topic/");
    }

    @Override
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        // TODO Auto-generated method stub

    }

}

切换回仅spring-boot-starter-websocket依赖项的1.1.9.RELEASE(并将所有其他spring
boot依赖项保持在1.2.1.RELEASE和spring core保持在4.1.4),该异常消失。

看起来像个错误,但有人可以确认吗?

更新 :更多上下文-这是来自后端服务器代码-
没有websocket客户端连接到它。目的是通过RabbitMQ发布“有趣的”事件,然后从暴露Websocket端点的前端服务器上的客户端可以使用这些事件。我的前端服务器上的代码通过Socksjs支持添加了端点:

public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint("/push").withSockJS();
}

从这个角度来看,我的理解根本上是有缺陷的:),或者Spring在检查始终应该有一个websocket端点时变得过于狂热。


阅读 1082

收藏
2020-05-30

共1个答案

小编典典

问题的根源在于您尚未在中配置任何端点registerStompEndpoints。尝试使用STOMP但尚未配置任何STOMP端点的应用程序将无法正常运行。

当您使用Spring Boot 1.1.9.RELEASE时,您的类路径中将包含一些Spring Framework 4.0.x jar。Spring
Framework 4.0.x的WebSocket支持不会注意到配置错误,即使您的应用无法运行,它也可以启动您的应用。Spring Framework
4.1的WebSocket支持会注意到此配置错误并引发异常,从而使您警惕该问题。

2020-05-30