首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 开源软件 >

spring宣言式事务管理配置方式

2012-11-23 
spring声明式事务管理配置方式最近学习了一下spring事务管理,这里总结一下几种不同的配置方法,如下图:1、通

spring声明式事务管理配置方式
最近学习了一下spring事务管理,这里总结一下几种不同的配置方法,如下图:

1、通过代理实现,每个bean一个代理

<bean id="userServiceProxy"ref="userService" /><property name="transactionManager" ref="txManager" /><property name="transactionAttributes"><props><!-- PROPAGATION_REQUIRED,readOnly,-MyCheckedException(其中-代表撤销,+代表提交) --><prop key="add*">PROPAGATION_REQUIRED</prop></props></property></bean>

2、使用拦截器
<bean id="transactionInterceptor"/></property><property name="transactionAttributes"><props><prop key="add*">PROPAGATION_REQUIRED</prop></props></property></bean><beanname="code"><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="*" propagation="REQUIRED" /></tx:attributes></tx:advice><aop:config><!-- |第一个 * —— 通配 任意返回值类型| --><!-- |第二个 * —— 通配 包com.evan.crm.service下的任意class| --><!-- |第三个 * —— 通配 包com.evan.crm.service下的任意class的任意方法| --><!-- |第四个 .. —— 通配 方法可以有0个或多个参数| --><aop:pointcut id="allPoint"expression="execution (* com.dreams.spring.tx.jdbc.*.*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="allPoint" /></aop:config>

4、注解(需要在类或方法上添加注解@Transactional
<tx:annotation-driven transaction-manager="txManager" />


示例代码:见附件。

热点排行