他的回复:
感谢开发人员的支持,这里根据CSE文档 和 华为云官网资料demo简单修改一下,复现问题服务提供者声明接口如下:@RestSchema(schemaId = "hello") @RestController @RequestMapping(path = "/") public class HelloService { @RequestMapping(path = "hello", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON) public SimpleRet sayHello(@RequestBody Person person) { return new SimpleRet("Hello " + person.getName() + ", you are " + person.getAge() + " years old."); } private class SimpleRet { private String result; public SimpleRet(String result) { this.result = result; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } } }Person类定义如下(age字段带有默认值):public class Person { private String name; private Integer age = 18; public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } }启动项目后请求获取结果服务消费者代码如下:@Component @EnableScheduling public class ConsumerScheduler implements BootListener { private RestTemplate restTemplate = RestTemplateBuilder.create(); private ObjectMapper objectMapper = new ObjectMapper(); private boolean allowRestCall = false; { restTemplate.setMessageConverters(Lists.newArrayList(new MappingJackson2HttpMessageConverter())); } @Scheduled(fixedRate = 10_000) public void doConsumePer10Sec() throws IOException { if (! allowRestCall) return; HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity requestEntity = new HttpEntity(objectMapper.readValue("{\"name\": \"Nick\"}", Object.class), headers); Object helloResult = restTemplate .postForObject("cse://provider-test/hello", requestEntity, Object.class); System.out.println(objectMapper.writeValueAsString(helloResult)); } @Override public void onBootEvent(BootEvent bootEvent) { if (bootEvent.getEventType().equals(EventType.AFTER_REGISTRY)) { allowRestCall = true; } } }打印结果如下,与预期不符(age字段变为null)问题现象:字段设置的默认值不生效,导致业务异常。