首先创建一个web工程就不用多说了,直接进入整合阶段。
第一步:加入Spring
1)首先导入Spring的jar包,解压spring-framework-4.0.1.RELEASE-dist压缩包,里面的lib文件夹全部导入
2)配置web.xml文件
org.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:applicationContext*.xml
3)加入Spring的配置文件: applicationContext.xml
第二步:加入hibernate
1)加入hibernate jar包
解压hibernate-release-4.2.4,文件夹\lib\required的全部文件
2)在类路径下加入hibernate.cfg.xml文件,在其中配置hibernate的基本属性
update
true
true
org.hibernate.dialect.MySQL5Dialect
3)建立持久化类,和其对应的.hbm.xml文件,生成对应的数据表
4)和spring进行整合
1.加入c3p0和MySQL的驱动
2.在applicationContext.xml文件里面配置:数据源,SessionFactory,声明式事务
3.启动项目,会在数据库看到对应的数据表
第三步:加入hibernate
1)加入jar包:解压struts-2.3.35 里面的apps\lib文件夹导入
2)在web.xml文件中配置Struts的Filter
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
3)加入Struts.xml文件(配置Action)
4) 整合spring :struts-2.3.35里面的lib文件夹(重复的删掉,版本低的删掉)
5)在Spring的配置文件里面配置Action时,Action的scope 的属性为prototype
6)在 Struts2 的配置文件Struts.xml中配置 Action 时, class 属性指向该 Action 在 IOC(applicationContext.xml) 中的 id