微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

FeignClient可以解码响应

如何解决FeignClient可以解码响应

我在春季引导中使用FeignClient。我有一些问题。

我的配置文件是:

@Configuration
@EnableFeignClients
@Import( FeignClientsConfiguration.class )
public class FeignConfiguration
{
 @Bean
 public Client client()
{
    return new ApacheHttpClient();
}

@Bean
public FeignClientErrorDecoder errorDecoder()
   {
    return new FeignClientErrorDecoder( new FeignDecoder() );
   }

 }
 

FeignClient构建器:

  public <T> T build( Class<T> clazz,String url,RequestInterceptor interceptor,FallbackFactory<T> fallbackFactory )
{
    return HystrixFeign.builder()
                       .logLevel( Logger.Level.FULL )
                       .client( client )
                       .encoder( encoder )
                       .decoder( decoder )
                       .retryer( retryer )
                       .contract( contract )
                       .errorDecoder( errorDecoder )
                       .requestInterceptor( interceptor )
                       .target( clazz,url,fallbackFactory );

}
  @FeignClient( name = "http-client",configuration = FeignConfiguration.class,decode404 = true,fallbackFactory = NotificationFeignFallbackFactory.class )
  public interface NotificationFeignClient
  {
    @PostMapping( produces = APPLICATION_JSON_VALUE )
    <T> CompletableFuture<ResponseEntity<?>> doSend( @Valid @RequestBody T data );

  }

当我得到回应时,我会遇到类似这样的异常:

  feign.codec.DecodeException: Error while extracting response for type                      
  [java.util.concurrent.CompletableFuture<org.springframework.http.ResponseEntity<?>>]
  and content type [application/json]; nested exception is               
  org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error:  
  Unrecognized token 'Body': was expecting (JSON String,Number,Array,Object or token 
  'null','true' or 'false'); nested exception is  
  com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'Body': was expecting 
  (JSON String,Object or token 'null','true' or 'false')
  at [Source: (pushbackinputstream); line: 1,column: 5]

就我而言,我想解析对CompletableFuture的响应。我该怎么办?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。