Struts2+Spring3+Hibernate3整合

准备三个框架结合的lib包
Spring3结合Struts2的步骤如下:
1:开启Struts2结合Spring3,在struts.xml中添加如下语句:

java代码:
  1. <constant name="struts.objectFactory" value="spring"/>  
2:在web.xml中添加listener,如下

java代码:
  1. <listener>  
  2.         <listener-class>  
  3. org.springframework.web.context.ContextLoaderListener</listener-class>  
  4.     </listener>  
3:在web.xml中指定需要初始读取的spring配置文件,如下:

java代码:
  1. <context-param>  
  2.     <param-name>contextConfigLocation</param-name>  
  3.     <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value>  
  4. </context-param>  
  5. 当然别忘了加上Struts2自己的filter  

4:在struts.xml中Action配置的时候,如下:

java代码:
  1. <action name="testAction" class="springBeanName">  
  2.     <result name="success">/index.jsp</result>  
  3. </action>  
5:在Spring中正常定义Bean就可以了,把Action定义成为Bean,如下:

java代码:
  1. <bean id="testAction" class="cn.javass.test.web.TestActioin">  
  2. <property name="ebi" ref="testEbi"/>  
  3. </bean>  
6:在Struts的Action中,就可以通过依赖注入的方式来注入需要使用的接口了。

猜你喜欢

转载自jenmhdn.iteye.com/blog/1631020