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