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

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

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

  2021-03-29 我要评论
想了解struts+spring+hibernate三个框架的整合的相关内容吗,在本文为您仔细讲解struts spring hibernate整合的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:struts,hibernate整合,struts2和spring整合,下面大家一起来学习吧。

准备三个框架结合的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三个框架的整合,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们