Question about Hessian integration in Spring Struts2

Source: Internet
Author: User

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

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.