java - 在 bean'subProtocolWebSocketHandler'中,Spring Boot web socket 1.2.1.release IllegalArgumentException: 没有处理程序

我希望将项目从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

web socket配置如下所示


@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),该异常消失。

前端服务器上的代码添加了支持Socksjs的端点:


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

时间:

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

Spring Framework 4.0.x 的WebSocket不会注意到配置错误,即使您的应用无法运行,它也可以启动您的应用。Spring Framework 4.1的WebSocket支持会注意到此配置错误并引发异常,您需要警惕该问题。

...