diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryBootstrapCustomizer.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryBootstrapCustomizer.java new file mode 100644 index 000000000000..05b2fbb7f767 --- /dev/null +++ b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryBootstrapCustomizer.java @@ -0,0 +1,49 @@ +package com.baeldung.serverconfig.server; + +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; +import org.springframework.stereotype.Component; +import reactor.netty.http.server.HttpServer; + +@Component +public class NettyWebServerFactoryBootstrapCustomizer implements WebServerFactoryCustomizer { + + @Override + public void customize(NettyReactiveWebServerFactory serverFactory) { + serverFactory.addServerCustomizers(new PortCustomizer(8443)); + serverFactory.addServerCustomizers(new EventLoopNettyCustomizer()); + } + + private static class PortCustomizer implements NettyServerCustomizer { + + private final int port; + + private PortCustomizer(int port) { + this.port = port; + } + + @Override + public HttpServer apply(HttpServer httpServer) { + return httpServer.port(port); + } + } + + private static class EventLoopNettyCustomizer implements NettyServerCustomizer { + + @Override + public HttpServer apply(HttpServer httpServer) { + EventLoopGroup parentGroup = new NioEventLoopGroup(); + EventLoopGroup childGroup = new NioEventLoopGroup(); + return httpServer + .tcpConfiguration(tcpServer -> tcpServer.bootstrap( + serverBootstrap -> serverBootstrap.group(parentGroup, childGroup).channel(NioServerSocketChannel.class) + )); + + } + + } +} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryPortCustomizer.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryPortCustomizer.java deleted file mode 100644 index 1dda58baa403..000000000000 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactoryPortCustomizer.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.baeldung.serverconfig.server; - -import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; -import org.springframework.boot.web.embedded.netty.NettyServerCustomizer; -import org.springframework.boot.web.server.WebServerFactoryCustomizer; -import org.springframework.stereotype.Component; -import reactor.netty.http.server.HttpServer; - -@Component -public class NettyWebServerFactoryPortCustomizer implements WebServerFactoryCustomizer { - - @Override - public void customize(NettyReactiveWebServerFactory serverFactory) { - serverFactory.addServerCustomizers(new PortCustomizer(8443)); - } - - private static class PortCustomizer implements NettyServerCustomizer { - - private final int port; - - private PortCustomizer(int port) { - this.port = port; - } - - @Override - public HttpServer apply(HttpServer httpServer) { - return httpServer.port(port); - } - } -} diff --git a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactorySslCustomizer.java b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactorySslCustomizer.java index 0aceae39dc74..d03c3a7f4079 100644 --- a/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactorySslCustomizer.java +++ b/spring-5-reactive-netty/src/main/java/com/baeldung/serverconfig/server/NettyWebServerFactorySslCustomizer.java @@ -1,6 +1,8 @@ package com.baeldung.serverconfig.server; import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory; +import org.springframework.boot.web.embedded.netty.SslServerCustomizer; +import org.springframework.boot.web.server.Http2; import org.springframework.boot.web.server.Ssl; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.stereotype.Component; @@ -16,7 +18,9 @@ public void customize(NettyReactiveWebServerFactory serverFactory) { ssl.setKeyAlias("alias"); ssl.setKeyPassword("password"); ssl.setKeyStorePassword("secret"); - serverFactory.setSsl(ssl); + Http2 http2 = new Http2(); + http2.setEnabled(false); + serverFactory.addServerCustomizers(new SslServerCustomizer(ssl, http2, null)); serverFactory.setPort(8443); } }