假装客户端未收到响应性
我正在学习假装(春季2.7.0,带有云2021.0.3)和我的微服务。服务之间的沟通在起作用,但我无法假装实际上获得响应性 - 只有DTO或列表。
我有一个服务端点,该端点返回响应范围中的列表:
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ApiController {
@GetMapping("/all")
ResponseEntity getAll() {
List<ApiKey> apiKeyList = apiService.getAll();
if ( apiKeyList == null || apiKeyList.size() < 1) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON)
.body(new ErrorResponse("No APIKeys were found "));
} else {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(apiKeyList);
}
该列表包含多个:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApiKey {
@NotNull
private String apiKey;
private UUID uuid;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate beginDate;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate endDate;
实际上调用的假装客户端:
@FeignClient(name = "identity-service")
public interface IdentityServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/api/all")
public List<ApiKey> getAllApiKeys();
// the above works, the below errors out:
public ResponseEntity getAllApiKeys();
因此,只要它期望列表keyresponse keyresponse,feign客户端就可以正常工作 但是我想在响应范围内拥有它,以便我可以任何潜在的状态代码。
我如何让Feign客户端与响应性合作?
I am learning Feign (Spring 2.7.0 with cloud 2021.0.3) with my micro-services. The communication between services is working but I am unable to have Feign actually receive a ResponseEntity - only the DTO or List.
I have a service endpoint that returns a list in a ResponseEntity:
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class ApiController {
@GetMapping("/all")
ResponseEntity getAll() {
List<ApiKey> apiKeyList = apiService.getAll();
if ( apiKeyList == null || apiKeyList.size() < 1) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).contentType(MediaType.APPLICATION_JSON)
.body(new ErrorResponse("No APIKeys were found "));
} else {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(apiKeyList);
}
The List contains multiple:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ApiKey {
@NotNull
private String apiKey;
private UUID uuid;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate beginDate;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
private LocalDate endDate;
The Feign client that actually makes the call is:
@FeignClient(name = "identity-service")
public interface IdentityServiceClient {
@RequestMapping(method = RequestMethod.GET, value = "/api/all")
public List<ApiKey> getAllApiKeys();
// the above works, the below errors out:
public ResponseEntity getAllApiKeys();
So the Feign client will work, as long as it expects List keyResponse
But I would like to have that in the ResponseEntity so that I can any potential status code.
How do I get feign client to work with ResponseEntity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果杰克逊在构建响应范围方面有问题,因为它没有no-args构造函数,请尝试使用响应式decoder
If jackson has issues with constructing the ResponseEntity because it has no no-args constructor try to use the ResponseEntityDecoder