I am using Spring MVC 4 and I want to know that I am using @RestController at class level and for one of its method I am Using @RequestMapping(headers = "Accept=application/json"). Now can any one tell me why just by using <mvc:annotation-driven /> in my config-servlet.xml how I am getting the response in JSON on my browser. I mean using header attribute is only saying that this method can only respond to requests having this type of headers. How does the MVC4 knows to respond in JSON on browser. Here is my code:
My config-servlet.xml
<beans>
<context:component-scan base-package="com.songs.service.controller" />
<mvc:annotation-driven />
</beans>
My RestController Class
@RestController
@RequestMapping("/songappWS")
public class SongServiceWS
{
@RequestMapping(value = "/topmoviesWS", method = RequestMethod.GET, headers="Accept=application/json")
public List<?> getTopMoviesWS() {
//method logic
return l1;
}
}