SpringBoot反应式协同路由器KSuspendFunction2

时间:2020-08-08 11:11:28

标签: spring-boot kotlin spring-webflux

我正在尝试与Kotlin一起使用springboot webflux。在实现路由器时,我在PersonRouteHandler :: getTest:

上收到此错误消息
Type mismatch:
Required: suspend (ServerRequest) -> ServerResponse
Found: KSuspendFunction2<PersonRouteHandler, ServerRequest, ServerResponse>

路由器:

@Component
class PersonRouter {

    @Bean
    suspend fun personRoutes() = coRouter {
        accept(MediaType.APPLICATION_JSON).nest(
                GET("/", PersonRouteHandler::getTest)
        )
    }
}

处理程序:

@Component
open class PersonRouteHandler {
    @Autowired
    lateinit var _personService: IPersonService

    @Autowired
    lateinit var _commandBus: CommandBus;

    suspend fun getTest(request: ServerRequest): ServerResponse =
        ServerResponse.ok().body(BodyInserters.fromValue("Hello")).awaitSingle()

    fun postTest(request: ServerRequest): Mono<ServerResponse> {
        val body = request.bodyToMono(PostPerson::class.java).single()

       return ServerResponse.ok().body(BodyInserters.fromValue("Hello"))
    }
}

0 个答案:

没有答案