<mvc:annotation-driven /> will do the following:
- Register DefaultAnnotationHandlerMapping with the spring container.
- Register the AnnotationMethodHandlerAdapter with the spring container.
- Configure some messageconverters.
- Resolved the premise configuration of the @Controller annotation, that is, HandlerMapping can know who handles the request.
<context:annotation-config /> will do the following:
- Register AutowiredAnnotationBeanPostProcessor with the spring container.
- Register CommonAnnotationBeanPostProcessor with the spring container.
- Register PersistenceAnnotationBeanPostProcessor with the spring container.
- Register RequiredAnnotationBeanPostProcessor with the spring container.
- Before using <context:annotationconfig />, the context namespace <context:component-scan /> must be declared in the <beans> element. <context:component-scan /> scans the package and implements annotation-driven bean definitions. That is, a bean of the class identified by @Controller is registered with the container.
<context:component-scan/>
Not only enables the scanning of class packages to implement annotation-driven bean definitions, but also enables annotation-driven automatic injection (that is, AutowiredAnnotationBeanPostProcessor and CommonAnnotationBeanPostProcessor are implicitly registered internally). Therefore, when using <context:component-scan />, you can remove <context:annotation-config /> unless you need to use the functions of PersistenceAnnotationBeanPostProcessor and RequiredAnnotationBeanPostProcessor (such as JPA, etc.).