3
這個問題是在問題的參考:使用ResponseEntity <t>
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)
...
但在春季API文檔中有一個靜態方法:
static HttpHeaders readOnlyHttpHeaders(HttpHeaders headers)
那麼它爲什麼會出現這樣的錯誤呢?
謝謝...
您使用的是哪個版本的spring-web.jar? – Ralph
@ralph:我正在使用_spring-web-3.0.6.RELEASE.jar_。 –
我看了一下代碼,它必須工作。仔細檢查一下你不使用該jar的不同(舊)版本。還仔細檢查一下你使用'org.springframework.http.HttpHeaders'而不是'org.commons.shomehting.HttpHeaders' – Ralph