编程语言
首页 > 编程语言> > SpringBoot 集成 WebSocket 遇到的问题 java.lang.IllegalStateException: Failed to register @ServerEndpoint

SpringBoot 集成 WebSocket 遇到的问题 java.lang.IllegalStateException: Failed to register @ServerEndpoint

作者:互联网

websocket server代码如下:


/**
 * websocket server类
 *
 * @author xzc
 * @data 2021/12/16
 */
@Slf4j
@Component
@ServerEndpoint(value = "/websocket/{type}")
public class WebSocketServer {

    ……
}

错误如下: 

java.lang.IllegalStateException: Failed to register @ServerEndpoint class: class com.test.websocket.WebSocketServer$$EnhancerBySpringCGLIB$$31689f61
 
javax.websocket.DeploymentException: Cannot deploy POJO class [com.xxx.WebSocketServer$$EnhancerBySpringCGLIB$$31689f61] as it is not annotated with @ServerEndpoint

后面那一串是代表类被CGLIB转换为了代理对象,什么情况下会被转换为代理对象?

AOP!

AOP!

AOP!

WebSocketServer这个类被切了,以至于@ServerEndPoint注解无法注入至对应的对象,导致报错;检查自己项目中的AOP切入点,包括springboot配置文件里的,排除掉 WebSocketServer不被切就可以了。

标签:lang,websocket,SpringBoot,EnhancerBySpringCGLIB,WebSocketServer,ServerEndpoint,A
来源: https://blog.csdn.net/houjiezhuang/article/details/121997179