SPRINGMVC annotation Configuration

Source: Internet
Author: User

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:

    1. Register the defaultannotationhandlermapping with the spring container.
    2. Register the Annotationmethodhandleradapter with the spring container.
    3. Configure some messageconverter.
    4. Addresses the premise configuration for @Controller annotations that handlermapping can know who is handling the request.

<context:annotation-config/> will do several things:

    1. Register the Autowiredannotationbeanpostprocessor with the spring container.
    2. Register the Commonannotationbeanpostprocessor with the spring container.
    3. Register the Persistenceannotationbeanpostprocessor with the spring container.
    4. Register the Requiredannotationbeanpostprocessor with the spring container.
    5. 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

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.