Асинхронная ошибка при работе webflux со встроенным котом - PullRequest
0 голосов
/ 27 сентября 2018

Я изучаю webflux и tomcat 9. Я сделал простое приложение с одним методом (API).Мне удалось запустить его со встроенным котом.Но когда я запрашиваю метод, я получаю ошибку.

Вот мой код:

    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)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:770)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Thread.java:745)
...