使用嵌入式 tomcat 运行的 webflux 上的异​​步错误

我正在学习 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)


牧羊人nacy
浏览 290回答 1
1回答

慕田峪9158850

这最初是由M. Deinum在评论中发布的:在ServletHttpHandlerAdapter未配置为异步处理。您必须在从 返回的 Wrapper 上将该asyncSupported属性设置为。但是我强烈建议使用 Spring Boot 而不是自己尝试这样做trueTomcat.addServlet
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java