我正在学习 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 startAsyncWARNING: 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)
1 回答
慕田峪9158850
TA贡献1794条经验 获得超7个赞
这最初是由M. Deinum在评论中发布的:
在
ServletHttpHandlerAdapter
未配置为异步处理。您必须在从 返回的 Wrapper 上将该asyncSupported
属性设置为。但是我强烈建议使用 Spring Boot 而不是自己尝试这样做true
Tomcat.addServlet
添加回答
举报
0/150
提交
取消