目标:将Spring Boot 1.x (webMvc)迁移到版本2 (webFlux),并将Spring Cloud Edgware SR2迁移到FinchleyM8(等待发布版本)。
问题:Feign -> OpenFeign。OpenFeign在底层使用RxJava,但WebFlux- Reactor3。当前使用Mono作为返回类型时,会出现错误:
Caused by: org.springframework.http.converter.HttpMessageConversionException: Type definition error: [simple type, class reactor.core.publisher.Mono]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of
reactor.core.publisher.Mono
(no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information
代码示例:
@FeignClient(name = "thirdpartyresource", url = "${third.party.resource.url}")
public interface ThirdPartyResource {
@PostMapping(value = "/validate", consumes = APPLICATION_FORM_URLENCODED_VALUE)
Mono<ValidationResultDto> validate(MultiValueMap multiValueMap); // WORKS BAD
// Single<ValidationResultDto> validate(MultiValueMap multiValueMap); WORKS WELL
}
问题: 我是否需要创建自己的单声道转换器,还是这是spring-cloud-starter-openfeign的某些问题,一切都应该开箱即用?