From 3985fbaef190b95d71ec458993fd58a527239045 Mon Sep 17 00:00:00 2001 From: Helius <wangdoubleone@gmail.com> Date: Wed, 26 May 2021 20:14:01 +0800 Subject: [PATCH] modify --- src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java b/src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java index 2ceb827..7b5cd3d 100644 --- a/src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java +++ b/src/main/java/com/xcong/excoin/netty/handler/WebSocketServerHandler.java @@ -5,6 +5,7 @@ import com.xcong.excoin.netty.common.Contans; import com.xcong.excoin.netty.common.NettyTools; import com.xcong.excoin.netty.dispatch.MsgDispatch; +import com.xcong.excoin.utils.SpringContextHolder; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.*; @@ -29,9 +30,11 @@ import static io.netty.handler.codec.http.HttpUtil.isKeepAlive; /** - * @author wzy - * @email wangdoubleone@gmail.com - * @date 2019-05-06 + * 项目启动时,在控制台有 + * Unable to proxy interface-implementing method [public final void io.netty.channel.ChannelInitializer.channelRegistered(io.netty.channel.ChannelHandlerContext) throws java.lang.Exception] because it is marked as final: Consider using interface-based JDK proxies instead! + * 输出 + * 表明,此类将走代理enhancerbyspringcglib代理 + * 此时,获取到此类将为null(不知道原因),从而导致netty连接在初始化时会有空指针异常 */ @Slf4j @Component @@ -44,8 +47,8 @@ private WebSocketServerHandshaker handshaker; - @Resource(name = "msgDispatch") - private MsgDispatch msgDispatch; +// @Resource(name = "msgDispatch") +// private MsgDispatch msgDispatch; @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { @@ -76,7 +79,7 @@ if (content.contains(Contans.HEART_BEAT)) { resetTimes(ctx.channel()); } else { - this.msgDispatch.webSocketDispatch(ctx, content); + SpringContextHolder.getBean(MsgDispatch.class).webSocketDispatch(ctx, content); } } catch (ClassCastException e) { content = ((CloseWebSocketFrame) frame).reasonText(); -- Gitblit v1.9.1