无法使用提供的参数调用“Mono.and()”

时间:2017-10-04 05:32:56

标签: spring kotlin spring-webflux

我正在尝试运行位于here的示例项目。但是,我看到了

Error:(38, 22) Kotlin: None of the following functions can be called with the arguments supplied: public final fun and(p0: ((Subscriber<in Any!>!) -> Unit)!): Mono<Void!>! defined in reactor.core.publisher.Mono public final fun and(p0: Publisher<*>!): Mono<Void!>! defined in reactor.core.publisher.Mono

ApiHandler.kt函数中的buildResponse类中的

internal class ApiHandler(val geoLocationService: GeoLocationService, val sunriseSunsetService: SunriseSunsetService,
                      val errorHandler: ErrorHandler) {

    private companion object {
        const val ADDRESS = "address"
    }

    internal fun getLocation(request: ServerRequest) =
        request.pathVariable(ADDRESS).toMono()
                .transform(this::buildResponse)
                .transform(this::serverResponse)
                .onErrorResume(errorHandler::throwableError)!!

    internal fun postLocation(request: ServerRequest) =
        request.extract<LocationRequest>()
                .map(LocationRequest::address)
                .transform(this::buildResponse)
                .transform(this::serverResponse)
                .onErrorResume(errorHandler::throwableError)!!

    internal fun buildResponse(address: Mono<String>) =
        address.transform(geoLocationService::fromAddress)
                .and(this::sunriseSunset, ::LocationResponse)

    internal fun sunriseSunset(geographicCoordinates: GeographicCoordinates) =
        geographicCoordinates.toMono().transform(sunriseSunsetService::fromGeographicCoordinates)

    internal fun serverResponse(locationResponseMono: Mono<LocationResponse>): Mono<ServerResponse> =
        locationResponseMono.flatMap { ok() withBody it }
}

我猜测自编写此代码后Spring API已发生变化,但我无法弄清楚要将.and(...)更改为。

1 个答案:

答案 0 :(得分:1)

我认为这与3.1.0中的Reactor Core API更改有关。

Mono.and()不再是返回元组的运算符,但它现在只关心完成信号(Mono<Void>)。您应该按照the Reactor release notes中的建议,将and()运算符替换为zipzipWith运算符。