websocket

部署时 java.lang.IllegalStateException: Failed to register @ServerEndpoint class:

Tomcat 日志如下:

2020-03-28 16:32:08,187 -Initializing ExecutorService 'applicationTaskExecutor'
2020-03-28 16:32:08,665 -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-28 16:32:08,669 -Application run failed
java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class net.unwi.ulog.domain.WebsocketServer
        at org.springframework.web.socket.server.standard.ServerEndpointExporter.registerEndpoint(ServerEndpointExporter.java:159)
  ...
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
        at java.lang.Thread.run(Thread.java:745)
Caused by: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/ws/init] : existing endpoint was class net.unwi.ulog.domain.WebsocketServer and new endpoint is class net.unwi.ulog.domain.WebsocketServer
        at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:180)
        at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:234)
        at org.springframework.web.socket.server.standard.ServerEndpointExporter.registerEndpoint(ServerEndpointExporter.java:156)
        ... 21 common frames omitted
2020-03-28 16:32:08,671 -Shutting down ExecutorService 'applicationTaskExecutor'

注意到下面一句,明显是重复注入了

Caused by: javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/ws/init] : existing endpoint was class net.unwi.ulog.domain.WebsocketServer and new endpoint is class net.unwi.ulog.domain.WebsocketServer

翻了几页博客都是参照

https://stackoverflow.com/questions/31178799/websocket-issue-multiple-endpoints-may-not-be-deployed-to-the-same-path

或者把 @Component 注解去掉。

但是服务器可以本机调试又404了,总不能打包一次改一次是吧!

这么一来,要么本机用额外的tomcat调试,要么...

https://blog.csdn.net/u011719271/article/details/102712113

最后我选择用上述文章中的第二种方法重做的模块,既然选择了springboot,就跟随他到死吧。