HttpServer tcpConfiguration 已弃用

Posted

技术标签:

【中文标题】HttpServer tcpConfiguration 已弃用【英文标题】:HttpServer tcpConfiguration Deprecated 【发布时间】:2021-07-24 10:44:19 【问题描述】:

我从 Spring 2.3.1.RELEASE 迁移到 2.4.5。

HttpServer tcpConfiguration 新版本已弃用。如何使用 Spring boot 2.4.5 配置 NioEventLoopGroup。

    public NettyReactiveWebServerFactory factory(NioEventLoopGroup eventLoopGroup) 
        NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
        factory.setServerCustomizers(Collections.singletonList(new NettyServerCustomizer() 
            @Override
            public HttpServer apply(HttpServer httpServer) 
                return httpServer.tcpConfiguration(tcpServer ->
                        tcpServer.bootstrap(serverBootstrap -> serverBootstrap.group(eventLoopGroup)
                                .channel(NioserverSocketChannel.class)));
            
        ));
        return factory;
    

【问题讨论】:

【参考方案1】:

您应该直接使用HttpServer#runOn API。上面的 sn-p 应该是这样的:

public NettyReactiveWebServerFactory factory(NioEventLoopGroup eventLoopGroup) 
    NettyReactiveWebServerFactory factory = new NettyReactiveWebServerFactory();
    factory.setServerCustomizers(Collections.singletonList(new NettyServerCustomizer() 
        @Override
        public HttpServer apply(HttpServer httpServer) 
            return httpServer.runOn(eventLoopGroup);
        
    ));
    return factory;

【讨论】:

以上是关于HttpServer tcpConfiguration 已弃用的主要内容,如果未能解决你的问题,请参考以下文章

jdk下httpserver源码解析

连接webSocket客户端时节点httpServer无法关闭

第7月第26天 iOS httpserver

netty httpserver

简单httpserver

tornado httpserver