I have a spring boot application in which I am creating a controller with @Controller annotation, when I tried to access the resource using the url it is showing me 404, "not found". But as soon as I add annotation @ResponseBody at class level or method level, it gives me desired output. I want to understand the role of @Responsebody here why it is affecting the url identification. As far as I know @ResponseBody deals with the responses.
When I have code like below -
@Controller
@RequestMapping(value = "test")
public class TestController {
@RequestMapping(value = "/m1")
public @ResponseBody String testMethod(){
return "Hello First Application";
}
}
It is giving me an exact output as Hello First Application
when I remove @ResponseBody from the method testMethod() it gives me the following output.
{
"timestamp": "2019-06-13T06:36:14.510+0000",
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/test/m1"
}
I am expecting a string as a response.