您的位置:首页 > 其它

ssh整合 初步

2010-08-20 14:58 344 查看
Struts2.1.6 + Spring2.5.6 + Hibernate3.3.2
1.需要的jar包列表
jar包名称 所在位置 说明
antlr-2.7.6.jar hibernate/lib/required 解析HQL
aspectjrt spring/lib/aspectj AOP
aspectjweaver .. AOP
cglib-nodep-2.1_3.jar spring/lib/cglib 代理,二进制增强
common-annotations.jar spring/lib/j2ee @Resource
commons-collections-3.1.jar hibernate/lib/required 集合框架
commons-fileupload-1.2.1.jar struts/lib struts
commons-io-1.3.2 struts/lib struts
commons-logging-1.1.1 单独下载,删除1.0.4(struts/lib) struts
spring
dom4j-1.6.1.jar hibernate/required 解析xml
ejb3-persistence hibernate-annotation/lib @Entity
freemarker-2.3.13 struts/lib struts
hibernate3.jar hibernate
hibernate-annotations hibernate-annotation/
hibernate-common-annotations hibernate-annotation/lib
javassist-3.9.0.GA.jar hiberante/lib/required hibernate
jta-1.1.jar .. hibernate transaction
junit4.5
mysql-
ognl-2.6.11.jar struts/lib
slf4j-api-1.5.8.jar hibernate/lib/required hibernate-log
slf4j-nop-1.5.8.jar hibernate/lib/required
spring.jar spring/dist
struts2-core-2.1.6.jar struts/lib
xwork-2.1.2.jar struts/lib struts2
commons-dbcp spring/lib/jarkata-commons
commons-pool.jar ..
struts2-spring-plugin-2.1.6.jar struts/lib

2. BestPractice:
a) 将这些所有的jar包保存到一个位置,使用的时候直接copy
3. 步骤
a) 加入jar包
b) 首先整合Spring + Hibernate
i. 建立对应的package
1. dao / dao.impl / model / service / service.impl/ test
ii. 建立对应的接口与类框架
1. S2SH_01
iii. 建立spring的配置文件(建议自己保留一份经常使用的配置文件,以后用到的时候直接copy改)
iv. 建立数据库
v. 加入Hibernate注解
1. 在实体类上加相应注解@Entity @Id等
2. 在beans配置文件配置对应的实体类,使之受管
vi. 写dao service的实现
vii. 加入Spring注解
1. 在对应Service及DAO实现中加入@Component,让spring对其初始化
2. 在Service上加入@Transactional或者使用xml方式(此处建议后者,因为更简单)
3. 在DAO中注入sessionFactory
4. 在Service中注入DAO
5. 写DAO与Service的实现
viii. 写测试
c) 整合Struts2
i. 结合点:Struts2的Action由Spring产生
ii. 步骤:
1. 修改web.xml加入 struts的filter
2. 再加入spring的listener,这样的话,webapp一旦启动,spring容器就初始化了
3. 规划struts的action和jsp展现
4. 加入struts.xml
a) 修改配置,由spring替代struts产生Action对象
5. 修改action配置
a) 把类名改为bean对象的名称,这个时候就可以使用首字母小写了
b) @Scope(“prototype”)不要忘记
iii. struts的读常量:
1. struts-default.xml
2. struts-plugin.xml
3. struts.xml
4. struts.properties
5. web.xml
iv. 中文问题:
1. Struts2.1.8已经修正,只需要改i18n.encoding = gbk
2. 使用spring的characterencoding
3. 需要严格注意filter的顺序
4. 需要加到Struts2的filter前面
v. LazyInitializationException
1. OpenSessionInViewFilter
2. 需要严格顺序问题
3. 需要加到struts2的filter前面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: