5
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2018-07-25 09:17:32.977 ERROR 8176 --- [           main] o.s.boot.SpringApplication               : Application run failed

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:184) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:173) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:52) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:157) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:121) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:885) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.finishRefresh(ServletWebServerApplicationContext.java:161) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140) ~[spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:327) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243) [spring-boot-2.0.3.RELEASE.jar:2.0.3.RELEASE]
    at com.rajan.WebsocketDemoApplication.main(WebsocketDemoApplication.java:10) [classes/:na]
Caused by: java.lang.IllegalArgumentException: No handlers
    at org.springframework.util.Assert.isTrue(Assert.java:116) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.start(SubProtocolWebSocketHandler.java:247) ~[spring-websocket-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181) ~[spring-context-5.0.7.RELEASE.jar:5.0.7.RELEASE]
    ... 15 common frames omitted
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
Rajan Patel
  • 55
  • 1
  • 6

1 Answers1

6

Hm. Looks like you don't register any endpoints via a WebSocketMessageBrokerConfigurer implementation and overriding its registerStompEndpoints(StompEndpointRegistry registry).

Exactly this is a place where StompSubProtocolHandler is added to that SubProtocolWebSocketHandler:

@Override
public StompWebSocketEndpointRegistration addEndpoint(String... paths) {
    this.subProtocolWebSocketHandler.addProtocolHandler(this.stompHandler);
    WebMvcStompWebSocketEndpointRegistration registration =
            new WebMvcStompWebSocketEndpointRegistration(paths, this.webSocketHandler, this.sockJsScheduler);
    this.registrations.add(registration);
    return registration;
}
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I added with public void registerStompEndPoints(StompEndpointRegistry registry) { registry.addEndpoint("/ws").withSockJS(); – Rajan Patel Jul 25 '18 at 15:16
  • Do you really implement a `WebSocketMessageBrokerConfigurer` there? Maybe you have a slightly different error... – Artem Bilan Jul 25 '18 at 15:27
  • Yes I have implemented websocketMessageBrokreConfigurer along with registry.setApplicationDestinationPrefixes("/app"); registry.enableSimpleBroker("/topic"); – Rajan Patel Jul 25 '18 at 15:43
  • Good. So, only what remains is a simple project from you somewhere on GitHub to let us to reproduce and play. – Artem Bilan Jul 25 '18 at 16:00
  • 1
    There was a typo instead of registerStompendPoints I wrote registerStompEndPoints – Rajan Patel Jul 25 '18 at 18:24
  • i think your problem is a bit not actual to this old question. Please, raise a new SO thread with more details. – Artem Bilan Feb 08 '19 at 14:23