使用 Feign 和 Spring MVC 时对 ResponseEntity 进行编码和解码?
Encode and Decode ResponseEntity when using Feign and Spring MVC?
我正在尝试使用动态伪装。但是我在转换来自 RequestMapping 的响应时遇到很多问题。
Controller.java :
@RequestMapping("/users")
public ResponseEntity<List<User>> sendUsers
MyFeignClient.java :
public interface MyFeignClient {
@RequestLine(value="GET /api/users")
ResponseEntity<List<User>> getUsers();}
MainClass.java :
MyFeignClient callService = Feign.builder()
.encoder(new Encoder.Default())
.decoder(new Decoder.Default())
.requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
.target(MyFeignClient.class, "http://localhost:8710");
然后:
ResponseEntity<List<User>> txnPool = callService.getUsers();
但是我有以下错误:
feign.codec.DecodeException User is not a type supported by this decoder
我该如何解决?
我使用 JacksonEncoder 和 JacksonDecoder 解决了这个问题
MyFeignClient callService = Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
.target(MyFeignClient.class, "http://localhost:8710");
我还添加了@Headers("Content-Type: application/json")
到我的Feign界面
我正在尝试使用动态伪装。但是我在转换来自 RequestMapping 的响应时遇到很多问题。
Controller.java :
@RequestMapping("/users")
public ResponseEntity<List<User>> sendUsers
MyFeignClient.java :
public interface MyFeignClient {
@RequestLine(value="GET /api/users")
ResponseEntity<List<User>> getUsers();}
MainClass.java :
MyFeignClient callService = Feign.builder()
.encoder(new Encoder.Default())
.decoder(new Decoder.Default())
.requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
.target(MyFeignClient.class, "http://localhost:8710");
然后:
ResponseEntity<List<User>> txnPool = callService.getUsers();
但是我有以下错误:
feign.codec.DecodeException User is not a type supported by this decoder
我该如何解决?
我使用 JacksonEncoder 和 JacksonDecoder 解决了这个问题
MyFeignClient callService = Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.requestInterceptor(new FeignConfig(props).getJwtRequestInterceptor())
.target(MyFeignClient.class, "http://localhost:8710");
我还添加了@Headers("Content-Type: application/json")
到我的Feign界面