AOP术语、事务控制

编程入门 行业动态 更新时间:2024-10-09 12:26:18

AOP<a href=https://www.elefans.com/category/jswz/34/1764124.html style=术语、事务控制"/>

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需要配置如下内容:

  1. 事务管理器,是实现了PlatformTransactionManager接口的对象。可以使用Spring提供的org、springframework.jdbc.datasorce.DaraSourceTranscationManger类
  2. 事务增强
  3. 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术语、事务控制

本文发布于:2024-02-06 14:45:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1749740.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:术语   事务   AOP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!