|
@@ -16,20 +16,15 @@
|
|
|
|
|
|
package sample;
|
|
package sample;
|
|
|
|
|
|
-import org.apache.catalina.Context;
|
|
|
|
-import org.apache.catalina.startup.Tomcat;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.context.ApplicationContext;
|
|
import org.springframework.context.ApplicationContext;
|
|
-import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
|
|
|
-import org.springframework.context.annotation.Bean;
|
|
|
|
-import org.springframework.context.annotation.ComponentScan;
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
+import org.springframework.context.annotation.*;
|
|
import org.springframework.http.server.reactive.HttpHandler;
|
|
import org.springframework.http.server.reactive.HttpHandler;
|
|
-import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
|
|
|
|
|
|
+import org.springframework.http.server.reactive.ReactorHttpHandlerAdapter;
|
|
import org.springframework.web.reactive.config.EnableWebFlux;
|
|
import org.springframework.web.reactive.config.EnableWebFlux;
|
|
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
|
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
|
|
-
|
|
|
|
-import javax.servlet.Servlet;
|
|
|
|
|
|
+import reactor.ipc.netty.NettyContext;
|
|
|
|
+import reactor.ipc.netty.http.server.HttpServer;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author Rob Winch
|
|
* @author Rob Winch
|
|
@@ -43,26 +38,19 @@ public class WebfluxFormApplication {
|
|
private int port = 8080;
|
|
private int port = 8080;
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
public static void main(String[] args) throws Exception {
|
|
- Object lock = new Object();
|
|
|
|
try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
|
try(AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
|
|
WebfluxFormApplication.class)) {
|
|
WebfluxFormApplication.class)) {
|
|
- synchronized (lock) {
|
|
|
|
- lock.wait();
|
|
|
|
- }
|
|
|
|
|
|
+ context.getBean(NettyContext.class).onClose().block();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- @Bean(destroyMethod = "stop", initMethod = "start")
|
|
|
|
- public Tomcat tomcat(ApplicationContext context) throws Exception {
|
|
|
|
|
|
+ @Profile("default")
|
|
|
|
+ @Bean
|
|
|
|
+ public NettyContext nettyContext(ApplicationContext context) {
|
|
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
|
|
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context)
|
|
.build();
|
|
.build();
|
|
- Servlet servlet = new ServletHttpHandlerAdapter(handler);
|
|
|
|
- Tomcat server = new Tomcat();
|
|
|
|
- server.setPort(this.port);
|
|
|
|
- server.getServer().setPort(this.port);
|
|
|
|
- Context rootContext = server.addContext("", System.getProperty("java.io.tmpdir"));
|
|
|
|
- Tomcat.addServlet(rootContext, "servlet", servlet);
|
|
|
|
- rootContext.addServletMapping("/", "servlet");
|
|
|
|
- return server;
|
|
|
|
|
|
+ ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
|
|
|
|
+ HttpServer httpServer = HttpServer.create("localhost", port);
|
|
|
|
+ return httpServer.newHandler(adapter).block();
|
|
}
|
|
}
|
|
}
|
|
}
|