One of the reasons the SSH framework is very popular is that spring can be seamlessly integrated with the STRUTS2 framework. When you use spring, you do not need to create a Web container manually, but instead create a spring container through a profile declaration.
In Web applications, there are two ways to create a spring container: To configure the use of the third party MVC framework in Web.xml to create
The first is more commonly used, the second method is only valid for a specific framework, this is not an introduction, the following only describes the first method.
In order for the spring container to start automatically with Tomcat/jboss, we used the Servletcontextlistener listener to complete it.
Let's take a look at the web.xml of the project to integrate the spring configuration.
<!--integration Spring-->
<listener>
<listener-class> org.springframework.web.context.contextloaderlistener</listener-class>
</listener>
< context-param>
<param-name>contextConfigLocation</param-name>
<param-value> Classpath:spring/applicationcontext.xml</param-value>
</context-param>
In the above configuration,
1, in Contextloaderlistener, the Contextloaderlistener listener implements the Servletcontextlistener interface. He automatically finds applicationcontext.xml files under Web/inf at the time of creation.
2, when need to import the configuration file has more than one need to make the Context-param label, to determine the profile file name. By looking for initialization parameters for contextconfiglocation.
public void contextinitialized (Servletcontextevent event) {
//1, Load Spring's web container
This.contextloader = Createcontextloader ();
2, initialize the Spring Web container and load the configuration file.
This.contextLoader.initWebApplicationContext (Event.getservletcontext ());
}
Approximate process for creating a spring container:
/**
* Create Contextloader. Can is overridden in subclasses.
* @return The new contextloader
*
/protected Contextloader Createcontextloader () {return
new Contextloader ();
}
Summary:
In the SSH framework, we can configure the spring container to start automatically with Tomcat/jboss, and so on, without having to manually open it. This is done through the listener, which automatically reads and loads the corresponding configuration file when the spring container is started.