我在 Spring Boot 中使用 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, Number, Array, Object or token 'null', 'true' or 'false')
at [Source: (PushbackInputStream); line: 1, column: 5]
就我而言,我想解析对 CompletableFuture 的响应。我该怎么做?