第一范文网 - 专业文章范例文档资料分享平台

Struts+Spring+Hibernate框架搭建

来源:用户分享 时间:2025/10/19 21:24:53 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

坚持

SSH框架的搭建

整合SSH框架

整合框架版本:hibernate-distribution-3.6.0.Final-dist + spring-framework-2.5.6.SEC01-with-dependencies + struts-2.1.8.1

一、 搭建工具

Windows 、 Tomcat 6.0+ 、MyEclipse、 SQLServer2008 R2 、 Google

二、创建工程

新建WEB项目工程(MyEclipse),包含web.xml配置文件。

三、添加框架环境Junit4

右击新建的项目,选择Build Path —> Add Library —> Junit —> 选择Junit4 —> 确定完成单元测试的添加。

四、添加框架环境Struts2

1.解压 struts-2.1.8.1 ,如下图所示:

可在apps文件里,随机选择一个.war文件解压,到WEB-INF→lib下的基础jar文件:

1

坚持

SSH框架的搭建

复制黏贴添加到项目工程的lib下。也可将lib下的全

部jar(71个)都复制到项目中来,不过很多用不到。我们崇尚即用即加的原则……

2. 配置struts.xml和 web.xml文件,如下: web.xml:

xmlns=\

xsi:schemaLocation=\id=\ version=\>

ItcastOA

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndE

struts2 /*

http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\

xecuteFilter

index.html index.htm index.jsp default.html default.htm default.jsp

struts.xml:

\

2

坚持

SSH框架的搭建

\>

五、添加框架环境Hibernate3.6

1.添加jar包:核心包hibernate3.jar、依赖包:...\\lib\\required中的所有jar包、hibernate-jpa-2.0-api-1.0.0.Final.jar、c3p0-0.9.1.jar(数据库连接池必须)、sqljdbc4.jar(sqlserver数据库驱动)。至此jar包添加OK。

2.添加hibernate.cfg.xml、***.hbm.xml配置文件。配置文件如下: hibernate.cfg.xml:

\>

name=\>org.hibernate.dialect.SQLServerDialect

name=\>com.microsoft.jdbc.sqlserver.SQLServerDriver

name=\>jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test

sa

sqlserver true update

3

坚持

SSH框架的搭建

UsersInfo .hbm.xml:

\

\>

六、添加框架环境Spring2.5

1.添加jar包,核心包spring.jar、依赖包: aspectjrt.jar、aspectjweaver.jar、cglib-nodep-2.1_3.jar、commons-logging.jar

2.添加applicationContext.xml配置文件,修改如下: applicationContext.xml:

xmlns:xsi=\ xmlns:aop=\ xsi:schemaLocation=\

xmlns:tx=\

xmlns:context=\ http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx

http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop

http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/context

http://www.springframework.org/schema/context/spring-context-3.0.xsd \>

base-package=\>

4

坚持

SSH框架的搭建

七、整合Structs2与Spring

1.为什么整合?

Spring中有IOC容器,来管理对象,整合就是为了让Struts2中的action由IOC容器管理,从容器中管理对象,可以方便对对象注入属性,让Struts2对象管理的那一块变得更强大,由Spring管理。

2.在web.xml中配置Spring的监听器,添加代码如下:

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:applicationContext*.xml

listener-class>

3.添加struts2-spring-plugin-2.1.8.1.jar包,OK。

八、整合Hibernate与Spring

1.为什么整合?

目的1,由spring容器管理SesionFactory实例(只需要一个); 目的2,声明式事务管理。

2.在applicationContext.xml中配置SessionFactory对象:

/>

class=\>

5

value=\>

value=\>

搜索更多关于: Struts+Spring+Hibernate框架搭建 的文档
Struts+Spring+Hibernate框架搭建.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c300wa7zjru6gjog0oh073pit886azp004xl_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top