struts2.0 spring2.5 hibernate3.3

aquahellishSoftware and s/w Development

Dec 13, 2013 (4 years and 19 days ago)

456 views

struts2.0 spring2.5 hibernate3.3
整合


一、整合
jar










首先下载
3
个框架









struts2.0











下载地





http://apache.freelamp.com/struts/binaries/struts
-
2.0.14
-
all.zip









spring2.5










下载地





http://s3.amazonaws.com/dist.springframework.org/release/SPR/spring
-
fra
mework
-
2.5.6.SEC01
-
with
-
dependencies.zip














hibernate3.3





下载地





http://downloads.sourceforge.net/project/hibernate/hibernate3/3.3.2.GA/hib
ernate
-
distribution
-
3.3.2.GA
-
dist.zip










struts/lib


找出以下
5

jar
文件

它们是使用
struts2
必须的
jar
文件













commons
-
logging
-
1.0.4.jar













freemarker
-
2.3
.8.jar













ognl
-
2.6.11.jar













struts2
-
core
-
2.0.11.1.jar













xwork
-
2.0.4.jar













再找出


struts2
-
spring
-
plugin
-
2.0.14.jar



它是
struts2

spring
整合必须的
jar
文件










spring/dist















spring.jar









spring/lib/aspectj




spring
中使用
aspectj
必须的
jar














aspectjrt.jar













aspectjweaver.jar









spring/lib/log4j













log4j
-
1.2.15.jar










hibernate/hibernate3.jar









hibernate/lib/required


所有
jar
文件

它们是使用
hibernate
必须的
jar
文件









注意其中有
slf4j
-
api
-
1.5.8.jar
文件

它只是一个规范









我们需要下载它对
log4j
实现的
jar
文件









下载地址

http://www.slf4j.org/dist/slf4j
-
1.5.2.zip









找出其中有一个
slf4j
-
log4j12
-
1.5.2.jar











以上一共
18

jar
文件












二、修改配置文件









web.xml











<?
xml

version="1.0"

encoding="UTF
-
8"
?>

<
web
-
app

version
="2.5"

xmlns
="http://java.sun.com/xml/ns/javaee"





xmlns:xsi
="http://www.w3.org/2001/XMLSchema
-
instance"





xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee






http://java.sun.com/xml/ns/javaee/web
-
app_2_5.xsd">





<
context
-
param
>









<
param
-
name
>
contextConfigLocation
</
param
-
name
>









<
param
-
value
>
classpath*:applicationContext
-
*.xml
</
param
-
value
>





</
context
-
param
>






<
filter
>









<
filter
-
name
>
struts2
</
filter
-
name
>









<
filter
-
class
>













org.apache.struts2.dispatcher.FilterDispatcher









</
filter
-
class
>





</
filter
>





<
filter
-
mapping
>









<
filter
-
name
>
struts2
</
filter
-
name
>









<
url
-
pattern
>
/*
</
url
-
pattern
>





</
filter
-
mapping
>










<
filter
>









<
filter
-
name
>
hibernateFilter
</
filter
-
name
>









<
filter
-
class
>













org.springframework.orm.hibernate3.support.OpenSessionInViewFilter









</
filter
-
class
>





</
filter
>





<
filter
-
mapping
>









<
filter
-
name
>
hibernateFilter
</
filter
-
name
>









<
url
-
pattern
>
*.action
</
url
-
pattern
>





</
filter
-
mapping
>















<
filter
>








<
filter
-
name
>
Spring

character

encoding

filter
</
filter
-
name
>








<
filter
-
class
>
org.springframework.web.filter.CharacterEncodingFilter
</
filter
-
class
>












<
init
-
param
>
















<
param
-
name
>
encoding
</
param
-
name
>
















<
param
-
value
>
GBK
</
param
-
value
>












</
init
-
param
>








</
filter
>








<
filter
-
mapping
>












<
filter
-
name
>
Spring

character

encoding

filter
</
filter
-
name
>












<
url
-
pattern
>
/*
</
url
-
pattern
>








</
filter
-
mapping
>










<
listener
>









<
listener
-
class
>













org.springframework.web.context.ContextLoaderListener









</
listener
-
class
>





</
listener
>






<
welcome
-
file
-
list
>









<
welcome
-
file
>
index.jsp
</
welcome
-
file
>





</
welcome
-
file
-
list
>

</
web
-
app
>



hibernate.cfg.xml

<?
xml

version="1.0"
?>

<!
DOCTYPE

hibernate
-
configuration

PUBLIC





"
-
//Hibernate/Hibernate

Configuration

DTD

3.0//EN"





"http://hibernate.sourceforge.net/hibernate
-
configuration
-
3.0.dtd"
>


<
hibernate
-
configuration
>





<
session
-
factory
>









<
property

name
="format_sql">
false
</
property
>









<
property

name
="show_sql">
true
</
property
>









<
property

name
="connection.driver_class">













org.gjt.mm.mysql.Driver









</
property
>









<
property

name
="connection.url">













jdbc:mysql://localhost:3306/s2sh









</
property
>









<
property

name
="connection.username">
root
</
property
>









<
property

name
="connection.password">
password
</
property
>









<
property

name
="dialect">













org.hibernate.dialect.MySQLDialect









</
property
>









<
property

name
="hbm2ddl.auto">
none
</
property
>









<
mapping

resource
="com/illu/pojo/User.hbm.xml"

/>





</
session
-
factory
>

</
hibernate
-
configuration
>


applicationContext.xml

<?
xml

version="1.0"

encoding="UTF
-
8"
?>

<
beans

xmlns
="http://www.springframework.org/schema/beans"





xmlns:xsi
="http://www.w3.org/2001/XMLSchema
-
instance"





xmlns:aop
="http://www.springframework.org/schema/aop"





xmlns:tx
="http://www.springframework.org/schema/tx"





xmlns:lang
="http://www.springframework.org/schema/lang"





xsi:schemaLocation
="









http://www.springframework.org/schema/beans

http://www.springframe
work.org/schema/beans/spring
-
beans
-
2.0.xsd









http://www.springframework.org/schema/lang

http://www.spr
ingframewo
rk.org/schema/lang/spring
-
lang
-
2.0.xsd










http://www.springframework.org/schema/tx

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









http://www.springframework.org/schema/aop

http://www.springframewor
k.org/schema/aop/spring
-
a
op.xsd">










<
bean

id
="sessionFactory"









class
="org.springframework.orm.hibernate3.LocalSessionFactoryBean">









<
property

name
="configLocation">













<
value
>
classpath:hibernate.cfg.xml
</
value
>









</
property
>





</
bean
>










<
bean

id
="hibernateTemplate"

class
="org.springframework.orm.hibernate3.
HibernateTemplate">









<
property

name
="sessionFactory">













<
ref

bean
="sessionFactory"/>









</
property
>





</
bean
>










<!
--

配置事务管理器

--
>






<
bean

id
="transactionManager"









class
="org.springframework.orm.hibernate3.HibernateTransactionManager
">









<
property

name
="sessionFactory">













<
ref

bean
="sessionFactory"

/>









</
property
>





</
bean
>






<!
--

配置事物传播特性

--
>





<
tx:advice

id
="txAdvice"

transaction
-
manager
="transactionManager">









<
tx:attributes
>













<
tx:method

name
="add*"

propagation
="REQUIRED"

/>













<
tx:method

name
="delete*"

propagation
="REQUIRED"

/>













<
tx:method

name
="modify*"

propagation
="REQUIRED"

/>













<
tx:method

name
="*"

read
-
only
="true"

/>









</
tx:attributes
>





</
tx:advice
>






<!
--

哪些类的哪些方法参与事物
,

(*

com.evan.crm.service.*.*(..))
中几个通配符的
含义:









第一个

*

——

通配

任意返回值类型









第二个

*

——

通配


com.evan.crm.service
下的任意
class









第三个

*

——

通配


com.evan.crm.service
下的任意
class
的任意方法









第四个

..

——

通配

方法可以有
0
个或多个参数









综上:包
com.evan.crm.service
下的任意
class
的具有任意返回值类型、任意数目
参数和任意名称的方法
--
>





<
aop:config
>









<
aop:pointcut

id
="allManagerMethod"













expression
="execution(*

com.struts2.service.*.*(..))"

/>









<
aop:advisor

pointcut
-
ref
="allManagerMethod"













advice
-
ref
="txAdvice"

/>





</
aop:config
>

</
beans
>