I have a simple @Controller
within a spring-mvc
environment. This is the Controller:
@Controll
Do you have a file named messaging-servlet.xml
that declares the web application context?
By default because you have named the DispatcherServlet messaging, Spring will try to locate that file.
I guess it's related to default view name resolution.
If you want a value returned by your handler method to be encoded as response body (in JSON, XML, etc), you need to annoate the method with @ResponseBody
, or annotate the whole controller with @RestController
(in Spring 4.x).
Otherwise, Spring tries to render a view with your return as model attribute. And since you didn't provide a name of a view to render, Spring tries to deduce it from request URL.
I had the same problem.
I fixed it by replacing @Controller
with @RestController
.
In addition to @axtvat, pay attention to the differences between @Cotroller and @RestController, @RestController fixed the issue for me. https://dzone.com/articles/spring-framework-restcontroller-vs-controller