{"id":35542,"date":"2025-05-04T17:40:54","date_gmt":"2025-05-04T09:40:54","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/35542.html"},"modified":"2025-05-04T17:40:54","modified_gmt":"2025-05-04T09:40:54","slug":"netty%e9%ab%98%e5%b9%b6%e5%8f%91%e8%81%8a%e5%a4%a9%e6%9c%8d%e5%8a%a1%e5%99%a8%e5%ae%9e%e6%88%98%ef%bc%9a%e5%8d%8f%e8%ae%ae%e8%ae%be%e8%ae%a1%e3%80%81%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e4%b8%8espring","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/35542.html","title":{"rendered":"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210"},"content":{"rendered":"<p id=\"main-toc\">\u76ee\u5f55<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B-toc\" style=\"margin-left:0px\">\u4e00\u3001\u6280\u672f\u9009\u578b<\/p>\n<p id=\"%E4%B8%80%E3%80%81%E9%A1%B9%E7%9B%AE%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E4%BE%9D%E8%B5%96%E9%85%8D%E7%BD%AE-toc\" style=\"margin-left:0px\">\u4e8c\u3001\u9879\u76ee\u521d\u59cb\u5316\u4e0e\u4f9d\u8d56\u914d\u7f6e<\/p>\n<p id=\"1.1%20%E5%88%9B%E5%BB%BA%20Maven%20%E9%A1%B9%E7%9B%AE-toc\" style=\"margin-left:40px\">1.1 \u521b\u5efa Maven \u9879\u76ee<\/p>\n<p id=\"%E4%BA%8C%E3%80%81%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:0px\">\u4e09\u3001\u670d\u52a1\u7aef\u5b9e\u73b0<\/p>\n<p id=\"2.1%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%90%AF%E5%8A%A8%E7%B1%BB%EF%BC%88ChatServer%EF%BC%89-toc\" style=\"margin-left:40px\">2.1 \u670d\u52a1\u7aef\u542f\u52a8\u7c7b\uff08ChatServer\uff09<\/p>\n<p id=\"2.2%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%A4%84%E7%90%86%E5%99%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%88ChatServerInitializer%EF%BC%89-toc\" style=\"margin-left:40px\">2.2 \u670d\u52a1\u7aef\u5904\u7406\u5668\u521d\u59cb\u5316\uff08ChatServerInitializer\uff09<\/p>\n<p id=\"2.3%20%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E5%99%A8%EF%BC%88ChatServerHandler%EF%BC%89-toc\" style=\"margin-left:40px\">2.3 \u6d88\u606f\u5904\u7406\u5668\uff08ChatServerHandler\uff09<\/p>\n<p id=\"%E4%B8%89%E3%80%81%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:0px\">\u56db\u3001\u5ba2\u6237\u7aef\u5b9e\u73b0<\/p>\n<p id=\"3.1%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%90%AF%E5%8A%A8%E7%B1%BB%EF%BC%88ChatClient%EF%BC%89-toc\" style=\"margin-left:40px\">3.1 \u5ba2\u6237\u7aef\u542f\u52a8\u7c7b\uff08ChatClient\uff09<\/p>\n<p id=\"3.2%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E5%A4%84%E7%90%86%E5%99%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%88ChatClientInitializer%EF%BC%89-toc\" style=\"margin-left:40px\">3.2 \u5ba2\u6237\u7aef\u5904\u7406\u5668\u521d\u59cb\u5316\uff08ChatClientInitializer\uff09<\/p>\n<p id=\"3.3%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E5%99%A8%EF%BC%88ChatClientHandler%EF%BC%89-toc\" style=\"margin-left:40px\">3.3 \u5ba2\u6237\u7aef\u6d88\u606f\u5904\u7406\u5668\uff08ChatClientHandler\uff09<\/p>\n<p id=\"%E5%9B%9B%E3%80%81%E6%A0%B8%E5%BF%83%E5%8A%9F%E8%83%BD%E6%89%A9%E5%B1%95-toc\" style=\"margin-left:0px\">\u4e94\u3001\u6838\u5fc3\u529f\u80fd\u6269\u5c55<\/p>\n<p id=\"4.1%20%E7%B2%98%E5%8C%85%2F%E6%8B%86%E5%8C%85%E5%A4%84%E7%90%86-toc\" style=\"margin-left:40px\">4.1 \u7c98\u5305\/\u62c6\u5305\u5904\u7406<\/p>\n<p id=\"4.2%20%E5%BF%83%E8%B7%B3%E6%A3%80%E6%B5%8B%E4%B8%8E%E8%BF%9E%E6%8E%A5%E4%BF%9D%E6%B4%BB-toc\" style=\"margin-left:40px\">4.2 \u5fc3\u8df3\u68c0\u6d4b\u4e0e\u8fde\u63a5\u4fdd\u6d3b<\/p>\n<p id=\"4.3%20%E7%BE%A4%E8%81%8A%E5%8A%9F%E8%83%BD%E5%AE%9E%E7%8E%B0-toc\" style=\"margin-left:40px\">4.3 \u7fa4\u804a\u529f\u80fd\u5b9e\u73b0<\/p>\n<p id=\"%E4%BA%94%E3%80%81%E8%BF%90%E8%A1%8C%E4%B8%8E%E6%B5%8B%E8%AF%95-toc\" style=\"margin-left:0px\">\u516d\u3001\u8fd0\u884c\u4e0e\u6d4b\u8bd5<\/p>\n<p id=\"%E5%85%AD%E3%80%81%E5%AE%8C%E6%95%B4%E4%BB%A3%E7%A0%81%E7%BB%93%E6%9E%84-toc\" style=\"margin-left:0px\">\u4e03\u3001\u5b8c\u6574\u4ee3\u7801\u7ed3\u6784<\/p>\n<p id=\"%E4%B8%83%E3%80%81%E5%85%B3%E9%94%AE%E7%82%B9%E6%80%BB%E7%BB%93-toc\" style=\"margin-left:0px\">\u516b\u3001\u5173\u952e\u70b9\u603b\u7ed3<\/p>\n<p id=\"%E5%85%AB%E3%80%81%E8%BF%9B%E9%98%B6%E4%BC%98%E5%8C%96%E6%96%B9%E5%90%91-toc\" style=\"margin-left:0px\">\u4e5d\u3001\u8fdb\u9636\u4f18\u5316\u65b9\u5411<\/p>\n<p id=\"%E5%8D%81%E3%80%81Netty%20%E9%AB%98%E5%B9%B6%E5%8F%91%E8%81%8A%E5%A4%A9%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-toc\" style=\"margin-left:0px\">\u5341\u3001Netty \u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/p>\n<p id=\"1.%20%E8%BF%9E%E6%8E%A5%E6%95%B0%E6%BF%80%E5%A2%9E%E5%AF%BC%E8%87%B4%E5%86%85%E5%AD%98%E6%B3%84%E9%9C%B2%E6%88%96%20OOM-toc\" style=\"margin-left:40px\">1. \u8fde\u63a5\u6570\u6fc0\u589e\u5bfc\u81f4\u5185\u5b58\u6cc4\u9732\u6216 OOM<\/p>\n<p id=\"2.%20%E9%AB%98%E5%B9%B6%E5%8F%91%E4%B8%8B%E6%B6%88%E6%81%AF%E4%B8%A2%E5%A4%B1%E3%80%81%E9%A1%BA%E5%BA%8F%E9%94%99%E4%B9%B1-toc\" style=\"margin-left:40px\">2. \u9ad8\u5e76\u53d1\u4e0b\u6d88\u606f\u4e22\u5931\u3001\u987a\u5e8f\u9519\u4e71<\/p>\n<p id=\"3.%20%E5%AE%A2%E6%88%B7%E7%AB%AF%E9%A2%91%E7%B9%81%E6%96%AD%E8%BF%9E%EF%BC%88%E5%BF%83%E8%B7%B3%E4%B8%A2%E5%A4%B1%EF%BC%89-toc\" style=\"margin-left:40px\">3. \u5ba2\u6237\u7aef\u9891\u7e41\u65ad\u8fde\uff08\u5fc3\u8df3\u4e22\u5931\uff09<\/p>\n<p id=\"4.%20%E7%BA%BF%E7%A8%8B%E9%98%BB%E5%A1%9E%E5%AF%BC%E8%87%B4%E5%8F%8D%E5%BA%94%E8%BF%9F%E9%92%9D-toc\" style=\"margin-left:40px\">4. \u7ebf\u7a0b\u963b\u585e\u5bfc\u81f4\u53cd\u5e94\u8fdf\u949d<\/p>\n<p id=\"5.%20%E7%B2%98%E5%8C%85%2F%E6%8B%86%E5%8C%85%E9%97%AE%E9%A2%98-toc\" style=\"margin-left:40px\">5. \u7c98\u5305\/\u62c6\u5305\u95ee\u9898<\/p>\n<p id=\"6.%20%E5%B9%BF%E6%92%AD%E6%B6%88%E6%81%AF%E6%80%A7%E8%83%BD%E7%93%B6%E9%A2%88-toc\" style=\"margin-left:40px\">6. \u5e7f\u64ad\u6d88\u606f\u6027\u80fd\u74f6\u9888<\/p>\n<p id=\"7.%20%E5%8D%95%E6%9C%BA%E6%89%BF%E8%BD%BD%E8%83%BD%E5%8A%9B%E6%9C%89%E9%99%90-toc\" style=\"margin-left:40px\">7. \u5355\u673a\u627f\u8f7d\u80fd\u529b\u6709\u9650<\/p>\n<p id=\"8.%20SSL%2FTLS%E5%8A%A0%E5%AF%86%E5%AF%BC%E8%87%B4%E5%90%9E%E5%90%90%E4%B8%8B%E9%99%8D-toc\" style=\"margin-left:40px\">8. SSL\/TLS\u52a0\u5bc6\u5bfc\u81f4\u541e\u5410\u4e0b\u964d<\/p>\n<p style=\"margin-left:40px\"><img loading=\"lazy\" decoding=\"async\" alt=\"\" height=\"2464\" src=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250504094049-68173621bf05f.png\" width=\"3936\"><\/p>\n<h2 id=\"%E4%B8%80%E3%80%81%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B\">\u4e00\u3001\u6280\u672f\u9009\u578b<\/h2>\n<table>\n<tbody>\n<tr>\n<td>\u6280\u672f<\/td>\n<td>\u7528\u9014<\/td>\n<\/tr>\n<tr>\n<td>Netty 4.x<\/td>\n<td>\u7f51\u7edc\u901a\u4fe1<\/td>\n<\/tr>\n<tr>\n<td>Java 8+<\/td>\n<td>\u57fa\u7840\u5f00\u53d1<\/td>\n<\/tr>\n<tr>\n<td>Maven<\/td>\n<td>\u9879\u76ee\u6784\u5efa<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 id=\"%E4%B8%80%E3%80%81%E9%A1%B9%E7%9B%AE%E5%88%9D%E5%A7%8B%E5%8C%96%E4%B8%8E%E4%BE%9D%E8%B5%96%E9%85%8D%E7%BD%AE\">\u4e8c\u3001\u9879\u76ee\u521d\u59cb\u5316\u4e0e\u4f9d\u8d56\u914d\u7f6e<\/h2>\n<h3 id=\"1.1%20%E5%88%9B%E5%BB%BA%20Maven%20%E9%A1%B9%E7%9B%AE\">1.1 \u521b\u5efa Maven \u9879\u76ee<\/h3>\n<p>\u5728 pom.xml \u4e2d\u6dfb\u52a0 Netty \u4f9d\u8d56\uff1a<\/p>\n<p>&lt;dependencies&gt;<br \/>\n    &lt;!&#8211; Netty \u6838\u5fc3\u4f9d\u8d56 &#8211;&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;io.netty&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;netty-all&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;4.1.68.Final&lt;\/version&gt; &lt;!&#8211; \u4f7f\u7528\u6700\u65b0\u7a33\u5b9a\u7248\u672c &#8211;&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n    &lt;!&#8211; JSON \u5e8f\u5217\u5316\uff08\u53ef\u9009\uff0c\u7528\u4e8e\u6d88\u606f\u5bf9\u8c61\u8f6c\u6362\uff09 &#8211;&gt;<br \/>\n    &lt;dependency&gt;<br \/>\n        &lt;groupId&gt;com.fasterxml.jackson.core&lt;\/groupId&gt;<br \/>\n        &lt;artifactId&gt;jackson-databind&lt;\/artifactId&gt;<br \/>\n        &lt;version&gt;2.15.2&lt;\/version&gt;<br \/>\n    &lt;\/dependency&gt;<br \/>\n&lt;\/dependencies&gt; <\/p>\n<hr>\n<h2 id=\"%E4%BA%8C%E3%80%81%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%AE%9E%E7%8E%B0\">\u4e09\u3001\u670d\u52a1\u7aef\u5b9e\u73b0<\/h2>\n<h3 id=\"2.1%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%90%AF%E5%8A%A8%E7%B1%BB%EF%BC%88ChatServer%EF%BC%89\">2.1 \u670d\u52a1\u7aef\u542f\u52a8\u7c7b\uff08ChatServer\uff09<\/h3>\n<p>\u670d\u52a1\u7aef\u542f\u52a8\u5668<\/p>\n<p>public class ChatServer {<br \/>\n    private final int port;<br \/>\n    public ChatServer(int port) {<br \/>\n        this.port = port;<br \/>\n    }<\/p>\n<p>    public void run() throws Exception {<br \/>\n        EventLoopGroup bossGroup = new NioEventLoopGroup(); \/\/ \u7528\u4e8e\u5904\u7406\u8fde\u63a5\u8bf7\u6c42<br \/>\n        EventLoopGroup workerGroup = new NioEventLoopGroup(); \/\/ \u7528\u4e8e\u5904\u7406\u6570\u636e\u8bfb\u5199<br \/>\n        try {<br \/>\n            ServerBootstrap b = new ServerBootstrap();<br \/>\n            b.group(bossGroup, workerGroup)<br \/>\n             .channel(NioServerSocketChannel.class)<br \/>\n             .childHandler(new ChatServerInitializer()) \/\/ \u914d\u7f6e\u5904\u7406\u5668\u94fe<br \/>\n             .option(ChannelOption.SO_BACKLOG, 128) \/\/ \u8fde\u63a5\u961f\u5217\u5927\u5c0f<br \/>\n             .childOption(ChannelOption.SO_KEEPALIVE, true); \/\/ \u4fdd\u6301\u8fde\u63a5<br \/>\n            \/\/ \u7ed1\u5b9a\u7aef\u53e3\u5e76\u542f\u52a8\u670d\u52a1\u5668<br \/>\n            ChannelFuture f = b.bind(port).sync();<br \/>\n            System.out.println(\\&#8221;\u670d\u52a1\u5668\u542f\u52a8\u6210\u529f\uff0c\u76d1\u542c\u7aef\u53e3\uff1a\\&#8221; + port);<br \/>\n            f.channel().closeFuture().sync();<br \/>\n        } finally {<br \/>\n            bossGroup.shutdownGracefully();<br \/>\n            workerGroup.shutdownGracefully();<br \/>\n        }<br \/>\n    }<\/p>\n<p>    public static void main(String[] args) throws Exception {<br \/>\n        int port = 8080;<br \/>\n        new ChatServer(port).run();<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"2.2%20%E6%9C%8D%E5%8A%A1%E7%AB%AF%E5%A4%84%E7%90%86%E5%99%A8%E5%88%9D%E5%A7%8B%E5%8C%96%EF%BC%88ChatServerInitializer%EF%BC%89\">2.2 \u670d\u52a1\u7aef\u5904\u7406\u5668\u521d\u59cb\u5316\uff08ChatServerInitializer\uff09<\/h3>\n<p>\u7ba1\u9053\u521d\u59cb\u5316\u5668<\/p>\n<p>public class ChatServerInitializer extends ChannelInitializer&lt;SocketChannel&gt; {<br \/>\n    @Override<br \/>\n    protected void initChannel(SocketChannel ch) throws Exception {<br \/>\n        ChannelPipeline pipeline = ch.pipeline();<\/p>\n<p>        \/\/ \u6dfb\u52a0\u7f16\u89e3\u7801\u5668\uff08\u5904\u7406\u6d88\u606f\u62c6\u5305\/\u7c98\u5305\uff09<br \/>\n        pipeline.addLast(new LengthFieldBasedFrameDecoder(1024 * 1024, 0, 4, 0, 4));<br \/>\n        pipeline.addLast(new LengthFieldPrepender(4)); \/\/ \u53d1\u9001\u6d88\u606f\u65f6\u6dfb\u52a0\u957f\u5ea6\u5b57\u6bb5<br \/>\n        \/\/ \u6dfb\u52a0\u5b57\u7b26\u4e32\u7f16\u89e3\u7801\u5668\uff08\u53ef\u66ff\u6362\u4e3a\u81ea\u5b9a\u4e49\u534f\u8bae\uff09<br \/>\n        pipeline.addLast(new StringDecoder());<br \/>\n        pipeline.addLast(new StringEncoder());<br \/>\n        \/\/ \u6dfb\u52a0\u81ea\u5b9a\u4e49\u5904\u7406\u5668<br \/>\n        pipeline.addLast(new ChatServerHandler());<br \/>\n    }<br \/>\n} <\/p>\n<h3 id=\"2.3%20%E6%B6%88%E6%81%AF%E5%A4%84%E7%90%86%E5%99%A8%EF%BC%88ChatServerHandler%EF%BC%89\">2.3 \u6d88\u606f\u5904\u7406\u5668\uff08ChatServerHandler\uff09<\/h3>\n<p>\u4e1a\u52a1\u903b\u8f91\u5904\u7406<\/p>\n<p>@Sharable<br \/>\npublic class ChatServerHandler extends SimpleChannelInboundHandler&lt;String&gt; {<br \/>\n    \/\/ \u5728\u7ebf\u7528\u6237\u5217\u8868\uff08\u7b80\u5316\u7248\uff0c\u5b9e\u9645\u5e94\u4f7f\u7528\u7ebf\u7a0b\u5b89\u5168\u7684\u96c6\u5408\uff09<br \/>\n    private static final Map&lt;String, Channel&gt; onlineUsers = new HashMap&lt;&gt;();<br \/>\n    @Override<br \/>\n    public void channelActive(ChannelHandlerContext ctx) throws Exception {<br \/>\n        System.out.println(\\&#8221;\u5ba2\u6237\u7aef\u8fde\u63a5\uff1a\\&#8221; + ctx.channel().remoteAddress());<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {<br \/>\n        \/\/ \u5904\u7406\u6d88\u606f\u903b\u8f91\uff08\u5982\u767b\u5f55\u3001\u804a\u5929\u3001\u7fa4\u53d1\u7b49\uff09<br \/>\n        if (msg.startsWith(\\&#8221;LOGIN:\\&#8221;)) {<br \/>\n            String username = msg.split(\\&#8221;:\\&#8221;)[1];<br \/>\n            onlineUsers.put(username, ctx.channel());<br \/>\n            ctx.writeAndFlush(\\&#8221;\u767b\u5f55\u6210\u529f\uff01\u5f53\u524d\u5728\u7ebf\u7528\u6237\uff1a\\&#8221; + onlineUsers.keySet());<br \/>\n        } else if (msg.startsWith(\\&#8221;SEND:\\&#8221;)) {<br \/>\n            String[] parts = msg.split(\\&#8221;:\\&#8221;);<br \/>\n            String toUser = parts[1];<br \/>\n            String content = parts[2];<br \/>\n            Channel toChannel = onlineUsers.get(toUser);<br \/>\n            if (toChannel != null &amp;&amp; toChannel.isOpen()) {<br \/>\n                toChannel.writeAndFlush(\\&#8221;\u6765\u81ea \\&#8221; + ctx.channel().remoteAddress() + \\&#8221; \u7684\u6d88\u606f\uff1a\\&#8221; + content);<br \/>\n            } else {<br \/>\n                ctx.writeAndFlush(\\&#8221;\u7528\u6237 \\&#8221; + toUser + \\&#8221; \u4e0d\u5728\u7ebf\uff01\\&#8221;);<br \/>\n            }<br \/>\n        } else {<br \/>\n            ctx.writeAndFlush(\\&#8221;\u672a\u77e5\u6307\u4ee4\uff0c\u8bf7\u4f7f\u7528 LOGIN:username \u6216 SEND:toUser:message\\&#8221;);<br \/>\n        }<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {<br \/>\n        cause.printStackTrace();<br \/>\n        ctx.close();<br \/>\n    }<\/p>\n<p>    @Override<br \/>\n    public void channelInactive(ChannelHandlerContext ctx) throws Exception {<br \/>\n        System.out.pri<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf19\u6b21\u30021.\u7f16\u89e3\u7801\u5668\uff1a\u901a\u8fc7\u89e3\u51b3\u7c98\u5305\u95ee\u9898\uff0c\u751f\u6210\u957f\u5ea6\u5b57\u6bb5\u30022.\u4e8b\u4ef6\u9a71\u52a8\uff1aNetty \u7684\u5904\u7406\u6d88\u606f\u3001\u8fde\u63a5\u72b6\u6001\u53d8\u5316\u7b49\u4e8b\u4ef6\u30023.\u8d44\u6e90\u7ba1\u7406\uff1a\u4f7f\u7528\u7ba1\u7406\u5728\u7ebf\u7528\u6237\uff0c\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u30024.\u6269\u5c55\u6027\uff1a\u901a\u8fc7\u7075\u6d3b\u6dfb\u52a0\u5904\u7406\u5668\uff08\u5982\u5b89\u5168\u8ba4\u8bc1\u3001\u65e5\u5fd7\u8bb0\u5f55\uff09\u3002\u7c98\u5305\u62c6\u5305\u5904\u7406\uff1a\u81ea\u5b9a\u4e49 $_ \u5206\u9694\u7b26\u5e7f\u64ad\u6d88\u606f\u7b80\u5355\u7684\u5f02\u5e38\u5904\u7406\u3002<\/p>\n","protected":false},"author":2,"featured_media":35541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[1826,98,220,2989],"topic":[],"class_list":["post-35542","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-server","tag-netty","tag-spring-boot","tag-220","tag-2989"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/35542.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf19\u6b21\u30021.\u7f16\u89e3\u7801\u5668\uff1a\u901a\u8fc7\u89e3\u51b3\u7c98\u5305\u95ee\u9898\uff0c\u751f\u6210\u957f\u5ea6\u5b57\u6bb5\u30022.\u4e8b\u4ef6\u9a71\u52a8\uff1aNetty \u7684\u5904\u7406\u6d88\u606f\u3001\u8fde\u63a5\u72b6\u6001\u53d8\u5316\u7b49\u4e8b\u4ef6\u30023.\u8d44\u6e90\u7ba1\u7406\uff1a\u4f7f\u7528\u7ba1\u7406\u5728\u7ebf\u7528\u6237\uff0c\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u30024.\u6269\u5c55\u6027\uff1a\u901a\u8fc7\u7075\u6d3b\u6dfb\u52a0\u5904\u7406\u5668\uff08\u5982\u5b89\u5168\u8ba4\u8bc1\u3001\u65e5\u5fd7\u8bb0\u5f55\uff09\u3002\u7c98\u5305\u62c6\u5305\u5904\u7406\uff1a\u81ea\u5b9a\u4e49 $_ \u5206\u9694\u7b26\u5e7f\u64ad\u6d88\u606f\u7b80\u5355\u7684\u5f02\u5e38\u5904\u7406\u3002\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/35542.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-04T09:40:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250504094049-68173621bf05f.png\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35542.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/35542.html\",\"name\":\"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-05-04T09:40:54+00:00\",\"dateModified\":\"2025-05-04T09:40:54+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/35542.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/35542.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/35542.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/35542.html","og_locale":"zh_CN","og_type":"article","og_title":"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1k\u6b21\uff0c\u70b9\u8d5e31\u6b21\uff0c\u6536\u85cf19\u6b21\u30021.\u7f16\u89e3\u7801\u5668\uff1a\u901a\u8fc7\u89e3\u51b3\u7c98\u5305\u95ee\u9898\uff0c\u751f\u6210\u957f\u5ea6\u5b57\u6bb5\u30022.\u4e8b\u4ef6\u9a71\u52a8\uff1aNetty \u7684\u5904\u7406\u6d88\u606f\u3001\u8fde\u63a5\u72b6\u6001\u53d8\u5316\u7b49\u4e8b\u4ef6\u30023.\u8d44\u6e90\u7ba1\u7406\uff1a\u4f7f\u7528\u7ba1\u7406\u5728\u7ebf\u7528\u6237\uff0c\u786e\u4fdd\u7ebf\u7a0b\u5b89\u5168\u30024.\u6269\u5c55\u6027\uff1a\u901a\u8fc7\u7075\u6d3b\u6dfb\u52a0\u5904\u7406\u5668\uff08\u5982\u5b89\u5168\u8ba4\u8bc1\u3001\u65e5\u5fd7\u8bb0\u5f55\uff09\u3002\u7c98\u5305\u62c6\u5305\u5904\u7406\uff1a\u81ea\u5b9a\u4e49 $_ \u5206\u9694\u7b26\u5e7f\u64ad\u6d88\u606f\u7b80\u5355\u7684\u5f02\u5e38\u5904\u7406\u3002","og_url":"https:\/\/www.wsisp.com\/helps\/35542.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-05-04T09:40:54+00:00","og_image":[{"url":"https:\/\/www.wsisp.com\/helps\/wp-content\/uploads\/2025\/05\/20250504094049-68173621bf05f.png"}],"author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/35542.html","url":"https:\/\/www.wsisp.com\/helps\/35542.html","name":"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-05-04T09:40:54+00:00","dateModified":"2025-05-04T09:40:54+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/35542.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/35542.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/35542.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Netty\u9ad8\u5e76\u53d1\u804a\u5929\u670d\u52a1\u5668\u5b9e\u6218\uff1a\u534f\u8bae\u8bbe\u8ba1\u3001\u6027\u80fd\u4f18\u5316\u4e0eSpring Boot\u96c6\u6210"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35542","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=35542"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/35542\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media\/35541"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=35542"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=35542"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=35542"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=35542"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}