S2SH框架集成步骤:
1、框架依赖jar文件
(这些jar包可以去官网自己下载,地址不在连接)
1.1 sping 所依赖工程 spring-framework-2.5.6
dist\spring.jar
lib\cglib\cglib-nodep-2.1_3.jar
lib\jakarta-commons\commons-logging.jar
lib\aspectj\aspectjweaver.jar和aspectjrt.jar lib\j2ee\common-annotations.jar
1.2 hibernate 所依赖工程 hibernate-distribution-3.3.2.GA
hibernate3.jar
lib\required\jta-1.1.jar javassist-3.9.0.GA.jar dom4j-1.6.1.jar commons-collections-3.1.jar antlr-2.7.6.jar slf4j-api-1.5.8.jar
lib\bytecode\cglib\cglib-2.2.jar
[二级缓存可选]lib\optional\oscache\oscache-2.1.jar 同时需要把\project\etc\oscache.properties 拷贝到src 下
[二级缓存可选]lib\optional\ehcache\ehcache-1.2.3.jar 同时需要把\project\etc\ehcache.xml
[二级缓存可选]lib\optional\c3p0\ 配置c3p0数据库连接池的使用 作用等同于apache的dbcp
*使用hibernate注解:hibernate-annotations-3.4.0.GA\
hibernate-annotations.jar
lib\hibernate-commons-annotations.jar
lib\ejb3-persistence.jar
*若使用slf的日志还需要:slf4j-1.5.8
slf4j-nop-1.5.8.jar
1.3 struts2 所依赖工程 struts-2.1.8.1
lib目录下的:
struts2-core-2.1.8.1.jar
xwork-core-2.1.6.jar
ognl-2.7.3.jar
freemarker-2.3.15.jar
commons-fileupload-1.2.1.jar
commons-io-1.3.2.jar
struts2-spring-plugin-2.1.8.1.jar
aopalliance-1.0.jar
classworlds-1.1.jar
commons-beanutils-1.7.0.jar
commons-chain-1.2.jar
commons-collections-3.2.jar 在hibernate中已经引用
commons-digester-2.0.jar
commons-lang-2.3.jar
commons-logging-1.0.4.jar 此文件在spring中已存在
commons-logging-api-1.1.jar
commons-validator-1.3.1.jar
ezmorph-1.0.3.jar
json-lib-2.1.jar 若使用json可选
oro-2.0.8.jar
oval-1.31.jar
2、框架的配置文件
2.1 spring框架配置文件及集成hibernate、二级缓存
$WEB_ROOT/WEB-INF/applicationContext.xml
src/ehcache.xml
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
">
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
cn/tsp2c/sshdemo/domain/User.hbm.xml
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
hibernate.show_sql=false
hibernate.format_sql=false
hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
其中集成hibernate需要属性文件:jdbc4mysql.properties
driverClassName=com.mysql.jdbc.Driver
url=jdbc\:mysql\://localhost\:3306/sshdemodb?useUnicode\=true&characterEncoding\=utf-8
username=root
password=1234
initialSize=1
maxActive=500
maxIdle=2
minIdle=1
需要配置hibernate的二级缓存,如使用ehcache:在src路径下加入ehcache.xml
timeToIdleSeconds="120"
timeToLiveSeconds="180"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="60"/>
overflowToDisk="true" timeToIdleSeconds="300" timeToLiveSeconds="500" diskPersistent="false"/>
2.2 struts2的配置文件: src/struts.xml
/p>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"">
/WEB-INF/page/message.jsp
/WEB-INF/page/error.jsp
/index.jsp
/login.jsp
/userlist.jsp
/useradd.jsp
3、需要把spring、strusts2框架注入到web容器(hibernate框架被spring集成,和web容器没有关系。所以不需要在web.xml中配置)
web.xml文件:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
">
contextConfigLocation
/WEB-INF/applicationContext.xml
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
org.springframework.web.context.ContextLoaderListener
index.jsp
3.1 web容器集成spring
contextConfigLocation
/WEB-INF/applicationContext.xml
org.springframework.web.context.ContextLoaderListener
3.2 web容器集成struts2
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
3.3 关于在session范围内解决hibernate的延迟加载问题
HibernateSessionInViewFilter
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
HibernateSessionInViewFilter
/*
4、如何使用s2sh框架实现MVC
4.1 action
struts.xml:
/userlist.jsp
/useradd.jsp
在spring中配置:
4.2 service
4.3 dao
posted on 2011-03-25 20:18 Soap MacTavish 阅读(3164) 评论(1) 编辑 收藏