如何解决:“没有适合newHandler的方法”

时间:2019-06-14 23:45:30

标签: java spring spring-boot

我正在尝试编写Spring Application。我的主要功能如下:


public static void main(String[] args) throws IOException 
{
        final BookServices bookService = new BookServices();
        final BookAPI bookAPI = new BookAPI(bookService);
        final RouterFunction<ServerResponse> routerFunction = RouterFunctions.
                nest(RequestPredicates.path("/"), bookAPI.routerFunction);
        final HttpHandler httpHandler = toHttpHandler(routerFunction);
        final ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(httpHandler);
        HttpServer server = HttpServer.create(HOST, PORT);
        server.newHandler(adapter).block();
}

不幸的是,此行引发错误:

        server.newHandler(adapter).block();

错误:

java: no suitable method found for newHandler(org.springframework.http.server.reactive.ReactorHttpHandlerAdapter)
    method reactor.ipc.netty.NettyConnector.newHandler(java.util.function.BiFunction<? super reactor.ipc.netty.http.server.HttpServerRequest,? super reactor.ipc.netty.http.server.HttpServerResponse,? extends org.reactivestreams.Publisher<java.lang.Void>>) is not applicable
      (argument mismatch; org.springframework.http.server.reactive.ReactorHttpHandlerAdapter cannot be converted to java.util.function.BiFunction<? super reactor.ipc.netty.http.server.HttpServerRequest,? super reactor.ipc.netty.http.server.HttpServerResponse,? extends org.reactivestreams.Publisher<java.lang.Void>>)
    method reactor.ipc.netty.http.server.HttpServer.newHandler(java.util.function.BiFunction<? super reactor.ipc.netty.http.server.HttpServerRequest,? super reactor.ipc.netty.http.server.HttpServerResponse,? extends org.reactivestreams.Publisher<java.lang.Void>>) is not applicable
      (argument mismatch; org.springframework.http.server.reactive.ReactorHttpHandlerAdapter cannot be converted to java.util.function.BiFunction<? super reactor.ipc.netty.http.server.HttpServerRequest,? super reactor.ipc.netty.http.server.HttpServerResponse,? extends org.reactivestreams.Publisher<java.lang.Void>>)

我正在使用Spring 2.1.5

0 个答案:

没有答案