title: How to customize Netty with Spring Boot 2.1 Webflux?
body: <p>I would like to customize Netty in my Spring Boot Webflux project. In my POM I added Spring Boot Webflux and Spring Boot Actuator dependencies. Next I overwrote the customize() method of WebServerFactoryCustomizer as described in the <a href="https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html#howto-configure-webserver" rel="nofollow noreferrer">Spring documentation</a>.</p>
  
  <pre><code>@Component
  public class NettyConfiguration implements WebServerFactoryCustomizer&lt;NettyReactiveWebServerFactory&gt; {
  
      @Override
      public void customize(NettyReactiveWebServerFactory factory) {
          factory.addServerCustomizers(new NettyCustomizer());
      }
  }
  </code></pre>
  
  <p>Then I implemented the Netty bootstrapping in my NettyCustomizer:</p>
  
  <pre><code>public class NettyCustomizer implements NettyServerCustomizer {
  
      private final EventLoopGroup bossGroup = new NioEventLoopGroup(22);
      private final EventLoopGroup workerGroup = new NioEventLoopGroup();
  
      @Override
      public HttpServer apply(HttpServer httpServer) {
          return httpServer.tcpConfiguration(tcpServer -&gt;
                  tcpServer.bootstrap(serverBootstrap -&gt;
                          serverBootstrap
                                  .group(bossGroup, workerGroup)
                                  .channel(NioServerSocketChannel.class)
                                  .handler(new LoggingHandler(LogLevel.DEBUG))
                                  .childHandler(new ChannelInitializer&lt;SocketChannel&gt;() {
                                      @Override
                                      public void initChannel(final SocketChannel socketChannel) {
                                          socketChannel.pipeline().addLast(new BufferingInboundHandler());
                                      }
                                  })
                                  .option(ChannelOption.SO_BACKLOG, 128)
                                  .childOption(ChannelOption.SO_KEEPALIVE, true))
                          .port(8899)
          );
      }
  }
  </code></pre>
  
  <p>Now if I start the Spring Boot application I get a "Unable to start Netty" error.</p>
  
  <pre><code>org.springframework.boot.web.server.WebServerException: Unable to start Netty
  Caused by: java.lang.IllegalStateException: group set already
  </code></pre>
  
  <p>So it seems there is no way to override Netty bootstrapping if using Webflux. Changing the addServerCustomizers() method to setServerCustomizers() in the customize() method leads to the same exceptions unfortunately. Does anybody know how to customize Netty together with Spring Boot?</p>