我正在学习 webflux 和 tomcat 9。我用单一方法(API)制作了一个简单的应用程序。我成功地使用嵌入式 tomcat 运行它。但是当我请求一个方法时,我得到了一个错误。
这是我的代码:
NewsRepository newsRepository = new DummyNewsRepository();
NewsHandler newsHandler = new NewsHandler(newsRepository);
RouterFunction<ServerResponse> newsRoute = route(GET("/news"), newsHandler::getNews);
HttpHandler httpHandler = RouterFunctions.toHttpHandler(newsRoute);
Servlet servlet = new ServletHttpHandlerAdapter(httpHandler);
Tomcat server = new Tomcat();
File base = new File(System.getProperty("java.io.tmpdir"));
Context rootContext = server.addContext("", base.getAbsolutePath());
Tomcat.addServlet(rootContext, "main", servlet);
rootContext.addServletMappingDecoded("/", "main");
server.setHostname("localhost");
server.setPort(8080);
server.getConnector();
server.start();
server.getServer().await();
和错误:
Sep 27, 2018 11:56:25 AM org.apache.catalina.connector.Request startAsync
WARNING: Unable to start async because the following classes in the processing chain do not support async [org.springframework.http.server.reactive.ServletHttpHandlerAdapter]
java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
at org.apache.catalina.connector.Request.startAsync(Request.java:1665)
at org.apache.catalina.connector.Request.startAsync(Request.java:1657)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1043)
at org.springframework.http.server.reactive.ServletHttpHandlerAdapter.service(ServletHttpHandlerAdapter.java:164)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
慕田峪9158850
相关分类