有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

JavaSpringBootWebSocket 1.2.1。在bean“subtocolWebSocketHandler”中释放IllegalArgumentException:无处理程序

所以我希望从SpringBoot1.1.9升级我的项目。发布至1.2.1。释放

    <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

    }

}

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

看起来像个bug,但有人能确认吗

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

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

从这个角度来看,要么我的理解存在根本性的缺陷:),要么Spring过于热衷于检查是否应该始终存在websocket端点


共 (1) 个答案

  1. # 1 楼答案

    问题的根源在于registerStompEndpoints中没有配置任何端点。试图使用STOMP但尚未配置任何STOMP端点的应用程序将无法正常工作

    当你使用Spring Boot 1.1.9时。发布后,您将拥有一些Spring Framework 4.0。在你的类路径上有x个罐子。Spring框架4.0。x的WebSocket支持不会注意到错误配置,并允许你的应用程序启动,即使它无法工作。Spring Framework 4.1的WebSocket支持会注意到这种错误配置,并引发异常,从而提醒您注意这个问题