我正在尝试与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"))
}
}