我有两个带Spring Boot的微服务。
微服务1
它是一个带方法的RestController。此方法返回ResponseEntity。我正在测试的用例在此ResponseEntity中返回以下内容 - >新的ResponseEntity(HttpStatus.UNPROCESSABLE_ENTITY)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<ServiceProvided> addService(@RequestBody ServiceProvided serviceProvided);
微服务2
它是另一个RestController,它有一个通过客户端调用微服务1的方法(@FergeClient ServiceProvidedManagementClient)。
RestController
@Autowired
private ServiceProvidedManagementClient serviceProvidedManagementClient;
@RequestMapping(value = "/create", consumes = "application/json", method = RequestMethod.POST)
public @ResponseBody ResponseEntity<ServiceProvided> createApplication(@RequestBody String service) {
ServiceProvided serviceProvided = ServiceMapper.convertToServiceProvided(service);
return serviceProvidedManagementClient.addService(serviceProvided);
}
客户端
@FeignClient(url = "localhost:8080")
public interface ServiceProvidedManagementClient {
@RequestMapping(value = "/services", method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<ServiceProvided> addService(@RequestBody ServiceProvided serviceProvided);
}
问题
例如,如果我通过SoapUi直接呼叫微服务1。我得到了我的预期。 JSON响应和原始响应中没有任何内容 - &gt; HTTP / 1.1 422 不可处理的实体
但如果我调用Microservice2(调用微服务1),我会得到另一个回复:
作为Json
{“timestamp”:1468221824521,“status”:500,“error”: “内部服务器错误”,“异常”:“feign.FeignException”,
“消息”:“状态422阅读 ServiceProvidedManagementClient#addService(ServiceProvided)”,
“path”:“/ services / create”}
As Raw - &gt; HTTP / 1.1 500 内部服务器错误
问题