术语、事务控制"/>
AOP术语、事务控制
AOP术语
Advice的类型
- 前置
- 后置
- 环绕
AOP配置
方式一:
<aop:config><aop:pointcut expression="excution()" id=""</aop:pointcut><!-- 前置增强 --><aop:aspect red=""><aop:beofre method="" pointcut-ref=""></aop:beofre><!-- 后置正常增强 --><aop:after-returning method="" pointcut-ref=""></aop:beofre><!-- 后置异常增强 --><aop:after-throwing method="" pointcut-ref=""></aop:beofre><!-- 后置增强 --><aop:after method="" pointcut-ref=""></aop:beofre><!-- 环绕增强 --><aop:around method="" pointcut-ref=""></aop:beofre></aop:aspect>
</aop:config>
方式二:每个类一个独立的增强类
<aop:config><!-- 配置切点 --><aop:pointcut expression="execution(public * com.yq.aop01.service..*.*(..))" id="pc1"/><!-- 配置切面 --><!-- <aop:aspect ref="adviceBO"><aop:before method="before1" pointcut-ref="pc1"/><aop:after-returning method="afterReturning" pointcut-ref="pc1" returning="retValue"/><aop:after-throwing method="afterThrowing" pointcut-ref="pc1" throwing="ex"/><aop:after method="after" pointcut-ref="pc1"/> <aop:around method="around" pointcut-ref="pcq"/></aop:aspect> --><!-- 配置前置增强 --><!-- <aop:advisor advice-ref="cusBef1" pointcut-ref="pc1"/> --><!-- 配置正常返回的后置增强 --><!-- <aop:advisor advice-ref="cusAft1" pointcut-ref="pc1"/> --><!-- 配置异常返回的后置增强 --><!-- <aop:advisor advice-ref="cusThr1" pointcut-ref="pc1"/> --><!-- 配置结束增强 --><!-- <aop:advisor advice-ref="cusAft2" pointcut-ref="pc1"/> --><!-- 配置环绕增强 --><aop:advisor advice-ref="cusAround1" pointcut-ref="pc1"/> </aop:config>
事务控制
声明式事务控制
xml需要配置如下内容:
- 事务管理器,是实现了PlatformTransactionManager接口的对象。可以使用Spring提供的org、springframework.jdbc.datasorce.DaraSourceTranscationManger类
- 事务增强
- AOP配置
<!-- 配置事务增强 --><tx:advice id="txMgr" transaction-manager="transactionManager"><tx:attributes><tx:method name="get*" read-only="true" propagation="REQUIRED"/><tx:method name="query*" read-only="true" propagation="REQUIRED"/><tx:method name="*" read-only="false" propagation="REQUIRED"/></tx:attributes></tx:advice><!-- 配置AOP切面 --><aop:config><aop:pointcut expression="execution(public * com.yq.tx01.service..*.*(..))" id="commDBPointcut"/><aop:advisor advice-ref="txMgr" pointcut-ref="commDBPointcut"/></aop:config><!-- 配置Dao --><bean class="com.yq.tx01.dao.impl.EmpDaoImpl" name="empDao" autowire="byType"/><bean class="com.yq.tx01.dao.impl.DeptDaoImpl" name="deptDao" autowire="byType"/><!-- 配置Service --><bean class="com.yq.tx01.service.impl.EmpServiceImpl" name="empService" autowire="byType"/>
更多推荐
AOP术语、事务控制
发布评论