这个问题引用了问题:
Setting the response content-type without using HttpServletResponse
使用以下代码:
@RequestMapping("handle.htm")
public ResponseEntity<String> handle() {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentType(new MediaType("text", "plain"));
//responseHeaders.set("myheader","xyz");
return new ResponseEntity<String>("Hello World", responseHeaders, HttpStatus.CREATED);
}
我收到以下错误:
java.lang.NoSuchMethodError: org.springframework.http.HttpHeaders.readOnlyHttpHeaders(Lorg/springframework/http/HttpHeaders;)Lorg/springframework/http/HttpHeaders;
org.springframework.http.HttpEntity.<init>(HttpEntity.java:100)
org.springframework.http.HttpEntity.<init>(HttpEntity.java:70)
org.springframework.http.HttpEntity.<clinit>(HttpEntity.java:58)
...
但是在 spring API 文档中有一个静态方法:
static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
那为什么会报这样的错误呢?
谢谢...
最佳答案
我已经查看了代码,它一定可以工作。仔细检查您不使用该 jar 的不同(旧)版本的所有内容。
关于spring - 使用 ResponseEntity<t>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8986249/