吃瓜~ 2019-01-23 16:39 采纳率: 50%
浏览 7135
已采纳

springboot2.0使用WebSocket 添加@Component启动报错

请教各位大佬:
springboot2.0使用WebSocket 添加@Component启动报错
使用springboot内置tomcat (Apache Tomcat/9.0.13)
下面是报错信息:


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-01-23 16:35:16.201 ERROR 6888 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class lmy.com.magic.controller.WebSockTest$$EnhancerBySpringCGLIB$$21e933ed
    at org.springframework.web.socket.server.standard.ServerEndpointExporter.registerEndpoint(ServerEndpointExporter.java:158) ~[spring-websocket-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.web.socket.server.standard.ServerEndpointExporter.registerEndpoints(ServerEndpointExporter.java:133) ~[spring-websocket-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.web.socket.server.standard.ServerEndpointExporter.afterSingletonsInstantiated(ServerEndpointExporter.java:111) ~[spring-websocket-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:863) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:863) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:546) ~[spring-context-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.1.RELEASE.jar:2.1.1.RELEASE]
    at lmy.com.magic.DemoApplication.main(DemoApplication.java:12) [classes/:na]
Caused by: javax.websocket.DeploymentException: Cannot deploy POJO class [lmy.com.magic.controller.WebSockTest$$EnhancerBySpringCGLIB$$21e933ed] as it is not annotated with @ServerEndpoint
    at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:202) ~[tomcat-embed-websocket-9.0.13.jar:9.0.13]
    at org.springframework.web.socket.server.standard.ServerEndpointExporter.registerEndpoint(ServerEndpointExporter.java:155) ~[spring-websocket-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    ... 12 common frames omitted

  • 写回答

2条回答 默认 最新

  • 迷途的小程序员 2019-06-24 14:57
    关注

    不知道你问题解决了没有,可能有其他人会翻到,我试着回答一下吧:
    首先参考了以下链接:http://www.pianshen.com/article/721751997/ ,了解到这个报错是因为websocket被代理了,像这个链接中的原因是切面,但是我的情况是没有用切面处理它,然后发现我的websocket实现类放的文件夹是service,联想到框架这种东西,在启动的时候做很多的初始化,可能是把这个类在启动的时候被当成了框架的业务层做了代理,所以我另外建了一个叫websocket的文件夹,把这个类往里面一丢就启动成功了。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效