The difference between the applicationcontext.xml in spring and the xxx-servlet.xml of SPRINGMVC
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 you 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.
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