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

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条)

报告相同问题?

悬赏问题

  • ¥15 软件定义网络mininet和onos控制器问题
  • ¥15 微信小程序 用oss下载 aliyun-oss-sdk-6.18.0.min client报错
  • ¥15 ArcGIS批量裁剪
  • ¥15 labview程序设计
  • ¥15 为什么在配置Linux系统的时候执行脚本总是出现E: Failed to fetch http:L/cn.archive.ubuntu.com
  • ¥15 Cloudreve保存用户组存储空间大小时报错
  • ¥15 伪标签为什么不能作为弱监督语义分割的结果?
  • ¥15 编一个判断一个区间范围内的数字的个位数的立方和是否等于其本身的程序在输入第1组数据后卡住了(语言-c语言)
  • ¥15 Mac版Fiddler Everywhere4.0.1提示强制更新
  • ¥15 android 集成sentry上报时报错。