下面列出了怎么用org.springframework.http.server.reactive.TomcatHttpHandlerAdapter的API类实例代码及写法,或者点击链接到github查看源代码。
@Bean
@Profile("default")
public Tomcat embeddedTomcatServer(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
Servlet servlet = new TomcatHttpHandlerAdapter(handler);
Tomcat tomcat = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootContext = tomcat.addContext("", base.getAbsolutePath());
Tomcat.addServlet(rootContext, "main", servlet).setAsyncSupported(true);
rootContext.addServletMappingDecoded("/", "main");
tomcat.setHostname("localhost");
tomcat.setPort(this.port);
tomcat.setBaseDir(System.getProperty("java.io.tmpdir"));
return tomcat;
}
private ServletHttpHandlerAdapter initServletAdapter() {
return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}
private ServletHttpHandlerAdapter initServletAdapter() {
return new TomcatHttpHandlerAdapter(resolveHttpHandler());
}