(1) To use spring in a Web project, you need to import a jar package:
Spring-web-4.2.4.jar Bag
(2) Configuring Listener in the Web. xml file
1 <listener>2 <listener-class>3 org.springframework.web.context.ContextLoaderListener4 </listener-class>5 </listener>
This contextloaderlistener it implements the Servletcontextlistener. In this listener, when the server is started, the object is ApplicationContext, In fact, it is an implementation of the class Webapplicationcontext, the object is deposited into the ServletContext.
(3) We also need to configure the location of the Applicationcontext.xml file in the Web. xml file, which is found by default in the Web-inf directory Applicationcontext.xml
If the Applicationcontext.xml file is not in the default location, we can configure it in the Web. xml file.
1 <context-param>2 <param-name>contextconfiglocation</param-name>3 <param-value >classpath:applicationcontext.xml</param-value>4 </context-param>
Classpath:applicationContext.xml it represents the current project under the Classpath (which can be understood to be in SRC) down to find the Applicationcontext.xml file.
Contextconfiglocation It is a constant declared in listener that describes the location of the spring configuration file.
With the above configuration, the spring framework can be used in web development.
The application of spring in web development