1. <mvc:annotation-driven/>
<mvc:annotation-driven/> is a shorthand form that registers defaultannotationhandlermapping and defaultannotationhandleradapt two beans by default , which is required by spring MVC to distribute the request to @controller, it also provides @numberformatannotation support, @DateTimeFormat support, @Valid support, read and write XML support (JAXB), Support for reading and writing JSON. You can also use the manual configuration of these two beans, but no shorthand for this way convenient.
2.<context:annotation-config/>
The role is to register Autowiredannotationbeanpostprocessor, Commonannotationbeanpostprocessor, Persistenceannotationbeanpostprocessor and Requiredannotationbeanpostprocessor the 4 beanpostprocessor. Registering these 4 beanpostprocessor functions is for your system to be able to identify the corresponding annotations
For example:
(1), if you want to use @autowired annotations, you must declare the Autowiredannotationbeanpostprocessor bean in the Spring container beforehand.
<bean class= "Org.springframework.beans.factory.annotation. Autowiredannotationbeanpostprocessor "/>
(2), if you want to use @Required annotations, you must declare the Requiredannotationbeanpostprocessor bean.
<Bean class="Org.springframework.beans.factory.annotation.RequiredAnnotationBeanPostProcessor" />
(3), if you want to use @ Resource, @ postconstruct, @ Predestroy and other annotations, you must declare the bean commonannotationbeanpostprocessor.
<Bean class="Org.springframework.beans.factory.annotation.CommonAnnotationBeanPostProcessor" />
(4), if you want to use @persistencecontext annotations, you must declare the Persistenceannotationbeanpostprocessor bean.
<Bean class=" Org.springframework.beans.factory.annotation.PersistenceAnnotationBeanPostProcessor "/>
Generally speaking, these annotations we are more commonly used, especially antowired annotations, in the automatic injection of the time is often used, so if you always need to follow the traditional way a configuration is a bit cumbersome and unnecessary, so spring provides us with <context: The simplified configuration of annotation-config/> automatically helps you to complete the declaration.
However, we typically use annotations to configure the scan package path option <context:component-scan base-package= "xx.xx"/>
This configuration item also includes the ability to automatically inject the above processor, so when you use <context:component-scan/>, you can remove <context:annotation-config/>.
SPRINGMVC Configuration Item Learning Notes