Spring引导websocket 1.2.1.RELEASE - bean中的IllegalArgumentException' subProtocolWebSocketHandler' :没有处理程序

时间:2015-02-12 03:18:04

标签: java spring spring-boot spring-websocket

所以我希望将我的项目从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引导依赖关系保持在1.2.1.RELEASE,弹簧核心保持在4.1.4),异常消失。 / p>

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

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

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

从这个角度来看,要么我的理解存在根本缺陷:),或者Spring在检查应该总是存在websocket端点时变得过于热心。

1 个答案:

答案 0 :(得分:3)

问题的根源在于您尚未在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支持会注意到这种错误配置并引发异常,从而提醒您注意该问题。