【Spring学习】Spring事物管理之aop技术
2015-04-30 15:47
375 查看
<?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:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> <!-- 配置事务管理器 --> <bean id="possTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource"><ref bean="dataSource" /></property> </bean> <!-- 事物管理名称: 配置事务的传播特性,配置一个切入点, 属面向切面编程, pointcut就是为了区分哪些方法需要被"加强" --> <tx:advice id="possTxAdvice" transaction-manager="possTransactionManager"> <tx:attributes> <tx:method name="*RdTx" propagation="REQUIRED" rollback-for="com.common.item.base.exception.TransactionException"/> <tx:method name="*SpTx" propagation="SUPPORTS" rollback-for="com.common.item.base.exception.TransactionException" /> <tx:method name="*NsTx" propagation="NOT_SUPPORTED" /> <tx:method name="*RnTx" propagation="REQUIRES_NEW" rollback-for="com.common.item.base.exception.TransactionException" /> </tx:attributes> </tx:advice> </beans>
<tx:advice/>配置详解
<tx:advice>:事务通知定义,用于指定事务属性,其中“transaction-manager”属性指定事务管理器,并通过< tx:attributes >指定具体需要拦截的方法;<tx:method name="save*">:表示将拦截以save开头的方法,被拦截的方法将应用配置的事务属性:propagation="REQUIRED" 表示传播行为是Required,isolation="READ_COMMITTED"表示隔离级别是提交读;
rollback-for:需要触发回滚的异常定义,以“,”分割,默认任何RuntimeException 将导致事务回滚,而任何Checked Exception 将不导致事务回滚;异常名字定义和TransactionProxyFactoryBean中含义一样
no-rollback-for:不被触发进行回滚的 Exception(s);以“,”分割;异常名字定义和TransactionProxyFactoryBean中含义一样;
timeout:事务超时时间设置,单位为秒,默认-1,表示事务超时将依赖于底层事务系统;
read-only:事务只读设置,默认为false,表示不是只读;
<!-- 配置事务拦截器拦截哪些类的哪些方法,一般设置成拦截Service -->
<aop:config> <aop:pointcut id="cncrowdServiceMethod" expression="execution(* com.cncrowd.mobile.service.*.*(..))" /> <aop:advisor advice-ref="possTxAdvice" pointcut-ref="cncrowdServiceMethod" /> </aop:config>
execution(* com.cncrowd.mobile.service.*.*(..))
这样写应该就可以了 这是com.cncrowd.mobile.service 包下所有的类的所有方法。。
第一个*代表所有的返回值类型
第二个*代表所有的类
第三个*代表类所有方法
最后一个..代表所有的参数。
相关文章推荐
- Spring学习(十三)aop技术理解与使用
- Spring学习之声明式事物管理
- ITCAST视频-Spring学习笔记(使用JDK中的Proxy技术实现AOP功能)
- SpringMVC + Spring + MyBatis 学习笔记:SpringMVC和Spring一同工作的时候,AOP事务管理不起作用的解决方法
- Spring学习之Spring AOP的底层实现技术
- [原创]java WEB学习笔记109:Spring学习---spring中事物管理
- 【Java EE 学习 77 上】【数据采集系统第九天】【通过AOP实现日志管理】【通过Spring石英调度动态生成日志表】【日志分表和查询】
- SSH学习——声明式事物管理(Spring)
- Spring核心技术--事物管理机制
- 【转】SSH学习——声明式事物管理(Spring)
- Spring.NET AOP技术学习
- SSH学习——声明式事物管理(Spring)
- 利用SpringAOP技术完成数据库连接事物实战
- springAOP事物管理不生效原因总结
- SpringAOP技术学习---Day1
- SpringAOP技术学习---Day2
- SpringAOP技术学习---Day3
- 框架学习—Spring的IOC容器之注解方式与AOP技术
- spring 学习基础笔记 包括spring 的代理 JDK CGLIB 事物 AOP 以及各种注入
- SpringAOP技术学习(4种技术总结)---Day4