我正在使用 Spring REST 模板从 REST 服务获取响应。我收到以下异常,但我无法找出问题所在。请找到以下详细信息。我错过了什么吗?
当我使用 Postman 尝试此操作时,我得到了正确的响应。
这里 AddFileServerBean 是请求:
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setBasicAuth(username, password);
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<AddFileServerBean> requestEntity = new HttpEntity<AddFileServerBean>(addFileServerBean,headers);
ResponseEntity<ResponseObject> response = restTemplate.exchange(endPointUrl, HttpMethod.POST, requestEntity, ResponseObject.class);
例外
Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.Assert.noNullElements(Ljava/util/Collection;Ljava/lang/String;)V
at org.springframework.web.client.HttpMessageConverterExtractor.<init>(HttpMessageConverterExtractor.java:77)
at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.<init>(RestTemplate.java:991)
at org.springframework.web.client.RestTemplate.responseEntityExtractor(RestTemplate.java:822)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:585)
at addfileserver.rest.FileRestTemplate.main(FileRestTemplate.java:280)
HttpMessageConverterExtractor 的源代码
@SuppressWarnings("unchecked")
HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters, Log logger) {
Assert.notNull(responseType, "'responseType' must not be null");
Assert.notEmpty(messageConverters, "'messageConverters' must not be empty");
Assert.noNullElements(messageConverters, "'messageConverters' must not contain null elements");
this.responseType = responseType;
this.responseClass = (responseType instanceof Class ? (Class<T>) responseType : null);
this.messageConverters = messageConverters;
this.logger = logger;
}
我预期的响应对象
{
"dataObj": {
"responseCode": 0,
"messageList": [
"Test"
],
"values": {
"uniqueId": "Test",
"pwd": "Test"
},
"objectValue": "-"
},
"applicationErrors": null
}