SPRINGMVC Configuration Item Learning Notes

Source: Internet
Author: User

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.


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.