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不被切就可以了。

上一篇:设计模式之装饰者模式


下一篇:装饰者模式