The difference between Applicationcontext-xxx.xml and Xxx-servlet.xml

Source: Internet
Author: User

1.applicationcontext.xml is a spring global configuration file that controls the spring features

2.dispatcher-servlet.xml is a spring MVC inside, controller, intercept URI forwarding view

3. If a bean is defined in two files (for example, two files define the same package as component scan), Spring generates an instance in both application context and servlet context. They are in different contexts, and they may behave differently.

4. If there is an instance of the same @Service in both the application context and the servlet context, the controller (in servlet context) passes the @Resource reference, The instance in the servlet context is selected first.

5. According to the website interpretation servlet context can refer to application context instances, and vice versa.

6. Multiple servlets sharing instances in application context

7. Recommended method: Servlet only scans @controler; Application Scan Other

Servlet.xml Scan Configuration

<!--The annotations in the scan package to generate the bean-->
<context:component-scan base-package= " Com.ssm.controller "use-default-filters=" false "
<context: Include-filter type= "Annotation"
expression= " Org.springframework.stereotype.Controller "/>
</context:component-scan

<context:component-scan base-package= "COM.SSM" use-default-filters= "true" >
<context:exclude-filter type= "Annotation"
expression= "Org.springframework.stereotype.Controller"/>
</context:component-scan>

The difference between Applicationcontext-xxx.xml and Xxx-servlet.xml

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.