Tuesday, November 2, 2010

Struts 2 + Spring 2.0 + Hibernate 3.0 Integration notes

1. Add Spring 2.0 Libraries

Select the following four jar, and configure to/WEB-INF/lib next
Spring2.0 AOP Libraries
Spring2.0 Core Libraries
Spring2.0 Persistence Core Libraries
Spring2.0 WEb Libraries
At the same time, the applicationContext.xml configuration to WEB/INF.

2. Add Hibernate 3.0 Libraries

Select from the following 2 jar, and configure to/WEB-INF/lib next
Hibernate 3.0 Core Libraries
hibernate 3.0 Advanced Support Libraries
While Hibernate file selection into applicationContext.xml (i.e., not individually create hibernate configuration files as resource files into applicationContext.xml)

3. Add commons-pool-1.4.jar and commons-dbcp-1.2.2.jar two jar to the lib, to eliminate the applicationContext.xml is not found in the class of errors

4. Add five struts2 to lib in jar

commons-logging-1.0.4.jar
freemarker-2.3.8.jar
ognl-2.6.11.jar
xwork-2.0.5.jar
struts-core-1.3.5.jar
Note: due to the integration of Spring, you also need to add struts2-spring-plugin-2.0.11.2.jar

5. Configuration web.xml

5.1 configuration application context spring
<!--Spring application context of-->
<context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
5.2 struts2 filter configuration

<!--Struts2 filters-->
<filter>
  <filter-name>struts2</filter-name>
  <filter-class>
   org.apache.struts2.dispatcher.FilterDispatcher
  </filter-class>
</filter>
<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>
5.3 listener configuration so that the spring at startup automatically loaded spring configuration
<!--Spring listener so that it automatically loads when you start spring configuration-->
<listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
</listener>
5.4 configuration OpenSessionInViewFilter filters, processing transactions
  <!--OpenSessionInViewFilter filters-->
<filter>
  <filter-name>lazyLoadingFilter</filter-name>
  <filter-class>
   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
  </filter-class>
</filter>
<filter-mapping>
  <filter-name>lazyLoadingFilter</filter-name>
  <url-pattern>*.action</url-pattern>
</filter-mapping>

6. configure struts.xml

Add a constant 6.1 will action submitted to the Spring handle
<constant name="struts.objectFactory" value="spring"></constant>
6.2 configuration action

7. will the action registered in struts.xml to applicationContext.xml in

8. the other ...

No comments:

Post a Comment