I have the following controller:
@RestController
@RequestMapping(value = "/base/url")
public class MyController {
@RequestMapping(
value = "/child/url",
method = RequestMethod.POST
)
@ResponseBody
public String mmm() {
return "Ok";
}
}
Now its working(server response Ok) but I thought that @ResponseBody redundant because we use @RestController and removed @ResponseBody annotation
and I see following server response:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Error 404 Not Found</title>
</head>
<body>
<h2>HTTP ERROR 404</h2>
<p>Problem accessing /base/url/child/url/Ok. Reason:
<pre> Not Found</pre>
</p>
<hr />
<i>
<small>Powered by Jetty://</small>
</i>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
</body>
</html>
Can you explain this behaviour ?
P.S.
Spring version: 4.1.6.RELEASE
P.S.
I have found only this part related to mvc config:
<context:annotation-config/>
<context:component-scan base-package="base.package"/>
To be able to use @RestController you have to explicitly enable the new annotation processing classes. By either adding <mvc:annotation-driven /> (for XML) or @EnableWebMvc (for Java Config).
By default the DispatcherServlet registers the, now deprecated, AnnotationMethodHandlerAdapter and DefaultAnnotationHandlerMapping which can be considered the predecessor or the newer stuff.
来源:https://stackoverflow.com/questions/35407390/restcontroller-without-responsebody-on-methods-work-incorrect