How the spring container is applied in Web applications, and how and when the Web container starts the spring container.
Don't say much, see Web.xml in several sections of configuration:
<!---① Load the spring configuration file from the Classpath->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
Classpath*:config/spring/common/appcontext-*.xml,
Classpath*:config/spring/local/appcontext-*.xml,
Classpath*:/config/spring/abtest/appcontext-*.xml,
Classpath*:/config/spring/pagelet/appcontext-pagelet-core.xml
</param-value>
</context-param>
<!--② is responsible for starting the listener for the spring container, which will obtain the spring configuration file address using the context parameters ①-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
The first thing to figure out is that this configuration file is Web.xml, so loading this file starts with a Web container. <context-param> configures the parameters of the Web container,<listener> defines a listener that is also part of the Web container startup. The Web container reads several configuration parameters that have loaded it, and then notifies its listeners via a servletcontextevent event: "I'm ready to go." An event is an event that contains the contents of the message, and this issue to Contextloaderlistener contains the context of the ServletContext, the Web container, The context of the Web container contains the Context-param (the parameters we configure at ①), so our contextloaderlistener can read our contextconfiglocation configuration information. Received the event notification, and from the notification event to get the configuration parameters, then go to the Balabala to start the spring container on the smooth.
But, in fact, there's a place up there where I'm not right, the listener listener not receive event notifications until the Web container is ready, but after all of the loading, the context of the Web container ServletContext initialized, and the notification is received. and listener received the event message is also just built up this servletcontext.
Initialization order of Web.xml: Context-param--> listener--> filter--> servlet.
What is classpath again? For example, after compiling this path for one of my projects:
Dish-server/target/dish-server-0.0.1-snapshot/web-inf
Web-inf contains the following:
Here classes and Lib are our abstract classpath.
1.classes contains all the compiled class files in our Web project and all the resource files under Resources in Java.
2.lib contains all of the jar packages we rely on.
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.