我有两个应用程序 A 和 B 使用 FeignClient 相互通信。作为应用程序 AI 希望对应用程序 B 返回的数据进行验证。如果我想验证请求参数,我可以轻松使用 @Valid 注释并使用正确的 spring 验证注释来注释对象。回应呢?
@FeignClient()
public interface AccountClient {
@PostMapping("/accounts/account/create")
void createAccount(@Valid CreateAccountRequest request);
@PostMapping("/accounts/account/get")
AccountResponse getAccount(AccountRequest request);
}
Run Code Online (Sandbox Code Playgroud)
public classs AccountResponse {
@NotNull
public String status;
}
Run Code Online (Sandbox Code Playgroud)
以代码为例。我可以轻松地验证应用程序 B 中的 CreateAccountRequest。但是 AccountResponse 呢?在这种情况下,@NotNull 不起作用。我宁愿避免获得响应并手动检查 status != null 因为我会有更多这样的字段。