The difference between the applicationcontext.xml in spring and the xxx-servlet.xml of SPRINGMVC in "reprint"

Source: Internet
Author: User

Never understand the difference between the two.
If SPRINGMVC is used, in fact, the bean configuration can be configured entirely in Xxx-servlet.xml. Why do I need applicationcontext.xml? Must be?
One
Because of the direct use of SPRINGMVC, So I have not understood how xxx-servlet.xml and Applicationcontext.xml are different, in fact, if the direct use of SPRINGMVC can not add Applicationcontext.xml file.
When using the Applicationcontext.xml file, you need to add listener in Web. XML:
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
This is generally a non-spring MVC architecture, such as using struts and so on, you want to introduce spring to add, this is used to load application Context.
If you are using SPRINGMVC directly, you just need to put all the relevant configuration into the Xxx-servlet.xml to be OK.
Two
Spring lets define multiple contexts in a parent-child hierarchy.
The applicationcontext.xml defines the beans for the "root webapp context" and i.e. the context associated with the WebApp.
The spring-servlet.xml (or whatever else call it) defines the beans for one servlet's app context. There can many of these in a webapp, one per Spring servlet (e.g. Spring1-servlet.xml for servlet spring1, Spring2-serv Let.xml for servlet spring2).
Beans in Spring-servlet.xml can reference Beans in Applicationcontext.xml, but not vice versa.
All Spring MVC controllers must go in the spring-servlet.xml context.
In more simple cases, the applicationcontext.xml context is unnecessary. It's generally used to contain beans, that's shared between all servlets in a webapp. If you are only having one servlet, then there's not really much point, unless has a specific use for it.



Disclaimer:
This article transfers from the network article, reproduced this article only for the personal collection, shares the knowledge, if has the infringement, please contact the blogger to delete.
Original zb0567
Original address: http://blog.csdn.net/zb0567/article/details/7930642

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.