Spring事务配置收集Word下载.docx
《Spring事务配置收集Word下载.docx》由会员分享,可在线阅读,更多相关《Spring事务配置收集Word下载.docx(26页珍藏版)》请在冰豆网上搜索。
1.0"
encoding="
UTF-8"
>
beansxmlns="
http:
//www.springframework.org/schema/beans"
xmlns:
xsi="
//www.w3.org/2001/XMLSchema-instance"
context="
//www.springframework.org/schema/context"
aop="
//www.springframework.org/schema/aop"
xsi:
schemaLocation="
//www.springframework.org/schema/beans
http:
//www.springframework.org/schema/beans/spring-beans-2.5.xsd
//www.springframework.org/schema/context
//www.springframework.org/schema/context/spring-context-2.5.xsd
//www.springframework.org/schema/aophttp:
//www.springframework.org/schema/aop/spring-aop-2.5.xsd"
<
beanid="
sessionFactory"
class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean"
propertyname="
configLocation"
value="
classpath:
hibernate.cfg.xml"
/>
configurationClass"
org.hibernate.cfg.AnnotationConfiguration"
/bean>
!
--定义事务管理器(声明式的事务)-->
transactionManager"
org.springframework.orm.hibernate3.HibernateTransactionManager"
ref="
--配置DAO-->
userDaoTarget"
com.bluesky.spring.dao.UserDaoImpl"
userDao"
org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
--配置事务管理器-->
target"
proxyInterfaces"
com.bluesky.spring.dao.GeneratorDao"
--配置事务属性-->
transactionAttributes"
props>
propkey="
*"
PROPAGATION_REQUIRED<
/prop>
/props>
/property>
/beans>
第二种方式:
所有Bean共享一个代理基类
transactionBase"
lazy-init="
true"
abstract="
parent="
第三种方式:
使用拦截器
transactionInterceptor"
org.springframework.transaction.interceptor.TransactionInterceptor"
beanclass="
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
beanNames"
list>
value>
*Dao<
/value>
/list>
interceptorNames"
transactionInterceptor<
第四种方式:
使用tx标签配置的拦截器
tx="
//www.springframework.org/schema/tx"
//www.springframework.org/schema/aop/spring-aop-2.5.xsd
//www.springframework.org/schema/txhttp:
//www.springframework.org/schema/tx/spring-tx-2.5.xsd"
context:
annotation-config/>
component-scanbase-package="
com.bluesky"
tx:
adviceid="
txAdvice"
transaction-manager="
attributes>
methodname="
propagation="
REQUIRED"
/tx:
advice>
aop:
config>
pointcutid="
interceptorPointCuts"
expression="
execution(*com.bluesky.spring.dao.*.*(..))"
advisoradvice-ref="
pointcut-ref="
/aop:
第五种方式:
全注解
annotation-driventransaction-manager="
propertyname