Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

When to use mvc annotation-driven in spring mvc?


Asked by Wren Paul on Dec 12, 2021 Spring



mvc:annotation-driven is used for enabling the Spring MVC components with its default configurations. If you dont include mvc:annotation-driven also your MVC application would work if you have used the context:component-scan for creating the beans or defined the beans in your XML file.
And,
@Controller annotation is an annotation used in Spring MVC framework (the component of Spring Framework used to implement Web Application). These classes (or its methods) are typically annotated also with @RequestMapping annotation that specify what HTTP Request is handled by the controller and by its method.
Similarly, The mvc:annotationDriven tag essentially sets you your Spring context to allow for dispatching requests to Controllers. The tag will configure two beans DefaultAnnotationHandlerMapping and AnnotationMethodHandlerAdapter. http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html
Also,
@EnableWebMvc - It is equivalent to mvc:annotation-driven in XML and it enables front controller to use @RequestMapping defined in our controller class to map incoming requests to anyparticular method.
Indeed,
Spring MVC framework provides different configuration elements that are helping or instructing the Spring container to effectively manage the beans and inject the beans when required. Some of the XML configurations that are most commonly seen in our spring configuration files are: