问题
So I'm looking to upgrade my projects from spring boot 1.1.9.RELEASE to 1.2.1.RELEASE.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
<version>${spring.boot.version}</version>
</dependency>
However, on startup, I gained:
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
Here's how my websocket configuration looks
@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
}
}
Switching back to 1.1.9.RELEASE of only the spring-boot-starter-websocket dependency (and keeping all other spring boot dependencies at 1.2.1.RELEASE and spring core at 4.1.4), the exception disappears.
Looks like a bug but can someone confirm?
UPDATE: More context - this is from a backend server code - no websocket clients connect to it. Intention is to publish 'interesting' events over RabbitMQ, which are then available to clients from front end servers that expose a websocket endpoint. Code on my front end servers add the endpoint with Socksjs support:
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/push").withSockJS();
}
From that standpoint, either my understanding is fundamentally flawed :), OR Spring has become overzealous in checking that there should be a websocket endpoint always.
回答1:
The root of the problem is that you haven't configured any endpoints in registerStompEndpoints
. An application that's trying to use STOMP, but has not configured any STOMP endpoints, won't work correctly.
When you're using Spring Boot 1.1.9.RELEASE you'll have some Spring Framework 4.0.x jars on your classpath. Spring Framework 4.0.x's WebSocket support doesn't notice the misconfiguration and allows your app to start even though it won't work. Spring Framework 4.1's WebSocket support notices this misconfiguration and throws an exception, thereby alerting you to the problem.
来源:https://stackoverflow.com/questions/28468685/spring-boot-websocket-1-2-1-release-illegalargumentexception-in-bean-subproto