Recently, during system transformation, we also encountered a problem: how to integrate Spring Struts2 and Hessian.
When Spring and Struts2 are configured, the following configuration is made in web. xml:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/spring/*.xml</param-value></context-param><listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class></listener>
Load the Spring context by setting listener, and set the object factory to Spring in struts. xml:
<constant name="struts.objectFactory" value="spring" />
In this way, Struts2 can use the action bean in the Spring context environment.
However, when configuring Hessian, it was previously configured in web. xml as follows:
<servlet> <servlet-name>Remoting</servlet-name> <servlet-class> org.springframework.web.servlet.DispatcherServlet </servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/spring/*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup></servlet><servlet-mapping> <servlet-name>Remoting</servlet-name> <url-pattern>/remoting/*</url-pattern></servlet-mapping>
When initializing the Hessian servlet, the Spring configuration file is used as a parameter again, which will generate a new Spring context environment, leading to repeated bean in Spring.
To solve this problem, modify Hessian as follows:
<Servlet> <servlet-name> Remoting </servlet-name> <servlet-class> org. springframework. web. servlet. dispatcherServlet </servlet-class> <init-param> <! -- <Param-name> contextConfigLocation </param-name> <param-value> classpath:/spring/*. xml </param-value> --> <! -- The spring context of this servlet uses WebApplicationContext and does not repeatedly generate context --> <param-name> contextAttribute </param-name> <param-value> org. springframework. web. context. webApplicationContext. ROOT </param-value> </init-param> <load-on-startup> 1 </load-on-startup> </servlet>
That is, when initializing Hessian, the Spring configuration file is not introduced, but the Spring WebApplicationContext context Context Environment initialized by listener, that is, the same context environment is used.
This article is from the "Learning document" blog, please be sure to keep this source http://zephiruswt.blog.51cto.com/5193151/1290391