为了账号安全,请及时绑定邮箱和手机立即绑定

来自 openfeign 和 Observable 的 @FeignClient 导致

来自 openfeign 和 Observable 的 @FeignClient 导致

噜噜哒 2022-11-30 16:33:56
我有一个带有以下假客户的项目@FeignClient(name = "name", url = "${tokenService}")public interface TokenService {    @RequestMapping(path = "/SLJsonWebTokenWrapper/token/wrap", method = RequestMethod.POST,        consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)    Observable<Token> getToken(@RequestHeader("externalSystemCode") String systemCode,                           @RequestBody TokenRequest tokenRequest);}和以下依赖org.springframework.cloud:spring-cloud-starter-feign一切正常。当我将项目更新为 Spring Boot 2(并使用org.springframework.cloud:spring-cloud-starter-openfeign)时,对此服务的请求因异常而失败c.f.j.d.e.InvalidDefinitionException: Cannot construct instance of `rx.Observable` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator) at [Source: (ByteArrayInputStream); line: 1, column: 2]at c.f.j.d.e.InvalidDefinitionException.from(InvalidDefinitionException.java:67)at c.f.j.d.DeserializationContext.reportBadDefinition(DeserializationContext.java:1452)at c.f.j.d.DeserializationContext.handleMissingInstantiator(DeserializationContext.java:1028)at c.f.j.d.d.BeanDeserializerBase.deserializeFromObjectUsingNonDefault(BeanDeserializerBase.java:1297)at c.f.j.d.d.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:326)at c.f.j.d.d.BeanDeserializer.deserialize(BeanDeserializer.java:159)at c.f.j.d.ObjectMapper._readMapAndClose(ObjectMapper.java:4013)at c.f.j.d.ObjectMapper.readValue(ObjectMapper.java:3084)... 1 frames excluded... 99 common frames omittedWrapped by: o.s.h.c.HttpMessageConversionException: Type definition error: [simple type, class rx.Observable]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `rx.Observable` (no Creators, like default construct, exist): cannot deserialize from Object value (no delegate- or property-based Creator)我该如何解决?PS 这个问题类似于Spring cloud netflix 和 HystrixObservable --> JsonMappingException,虽然没有答案
查看完整描述

2 回答

?
子衿沉夜

TA贡献1828条经验 获得超3个赞

添加此选项解决了我的问题

feign.hystrix.enabled: true


查看完整回答
反对 回复 2022-11-30
?
有只小跳蛙

TA贡献1824条经验 获得超8个赞

当您将 Feign 依赖项更改为:


<groupId>org.springframework.cloud</groupId>

<artifactId>spring-cloud-starter-openfeign</artifactId>

<version>2.1.0.RELEASE</version>

您的 Feign 客户端的注释也将更改为例如:


@FeignClient(name = "your-service-name", configuration = FeignConfig.class)


查看完整回答
反对 回复 2022-11-30
  • 2 回答
  • 0 关注
  • 91 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信