加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

struts+spring+hibernate三个框架的整合

发布时间:2020-12-14 14:10:15 所属栏目:Java 来源:网络整理
导读:准备三个框架结合的lib包 Spring3结合Struts2的步骤如下: 1:开启Struts2结合Spring3,在struts.xml中添加如下语句: java代码: constant name="struts.objectFactory" value="spring"/ 2:在web.xml中添加listener,如下: java代码: listener listener-

准备三个框架结合的lib包

Spring3结合Struts2的步骤如下:

1:开启Struts2结合Spring3,在struts.xml中添加如下语句:

java代码:

<constant name="struts.objectFactory" value="spring"/> 

2:在web.xml中添加listener,如下:

java代码:

<listener> 
    <listener-class> 
org.springframework.web.context.ContextLoaderListener</listener-class> 
  </listener> 

3:在web.xml中指定需要初始读取的spring配置文件,如下:

java代码:

<context-param> 
  <param-name>contextConfigLocation</param-name> 
  <param-value>/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml</param-value> 
</context-param> 

5.当然别忘了加上Struts2自己的filter  

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

java代码:

<action name="testAction" class="springBeanName"> 
  <result name="success">/index.jsp</result> 
</action>

5:在Spring中正常定义Bean就可以了,把Action定义成为Bean,如下:

java代码:

<bean id="testAction" class="com.bjpowernode.test.web.TestActioin"> 
<property name="ebi" ref="testEbi"/> 
</bean> 

6:在Struts的Action中,就可以通过依赖注入的方式来注入需要使用的接口了。

总结

以上所述是小编给大家介绍的struts+spring+hibernate三个框架的整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读