Let's look at a few confusing configurations for simplifying development: <mvc:annotation-driven/>, <context:annotation-config/>, <context: Component-scan/>.
<mvc:annotation-driven/> will do several things:
- Register the defaultannotationhandlermapping with the spring container.
- Register the Annotationmethodhandleradapter with the spring container.
- Configure some messageconverter.
- Addresses the premise configuration for @Controller annotations that handlermapping can know who is handling the request.
<context:annotation-config/> will do several things:
- Register the Autowiredannotationbeanpostprocessor with the spring container.
- Register the Commonannotationbeanpostprocessor with the spring container.
- Register the Persistenceannotationbeanpostprocessor with the spring container.
- Register the Requiredannotationbeanpostprocessor with the spring container.
- Before you use <context:annotationconfig/>, you must declare the context namespace <context:component-scan/> in the <beans> element. <context:component-scan/> Scans the package to implement the annotation driven Bean definition. That is, the bean that @Controller the class that is identified is registered in the container.
<context:component-scan/>Not only enables the ability to scan class packages to implement annotation-driven Bean definitions, but also enables annotation-driven auto-injection (that is, implicitly, internally registered Autowiredannotationbeanpostprocessor and Commonannotationbeanpostprocessor). So when using <context:component-scan/>, unless you need to use persistenceannotationbeanpostprocessor and Requiredannotationbeanpostprocessor two Processor functions (such as JPA, etc.), or you can remove <context:annotation-config/>
SPRINGMVC annotation Configuration