blue-sky blue-sky - 4 years ago 65
AngularJS Question

omitting Spring annotation @ResponseBody causes 404

Within my service if I omit the

then this service returns a 404 error but the service is successfully invoked.

Within the logs I receive this exception :

.10:00:38.716 [http-nio-8082-exec-10] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/app/services/myservice/log] in DispatcherServlet with name 'services'

is returning data which causes the invoking of the endpoint to not trigger a 404 ?

Here is how I'm invoking the service using AngularJS:

method : 'POST',
url : 'services/myservice/log'
}).error(function(data, status) {
alert('Error occurred '+status);

Answer Source

Adding a @ResponseBody or annotating your controller class as @RestController tells Spring to write the handler method return value directly to the HTTP Response Body. If you omit that, spring will try to resolve a view and since, i'm guessing, you do not define any appropriate View Resolver for that, it will return a 404 Not Found Error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download