Spring AOP中Pointcut,dvice 和 Advisor三个概念

mac2022-06-30  9

(1)切入点  Pointcut

              在介绍Pointcut之前,有必要先介绍  Join  Point(连接点)概念。

                         连接点:程序运行中的某个阶段点,比如方法的调用、异常的抛出等。比如方法doSome();

         Pointcut是JoinPoint的集合,它是程序中需要注入Advice 的位置的集合,指明Advice要在什么样的条件下才能被触发。

                   org.springframework.aop.Pointcut接口用来指定到特定的类和方法。

(2)通知Advice

 它是某个连接点所采用的处理逻辑,也就是向连接点注入的代码。例如:输出的日志信息   就是一个Advice

(3)Advisor

Advisor是Pointcut和Advice的配置器,它包括Pointcut和Advice,是将Advice注入程序中Pointcut位置的代码

 

 

<aop:aspectj-autoproxy/> <aop:config proxy-target-class="true"> <aop:pointcut id="servicePointcut" expression="execution(* com.cpic..*Service.*(..))" /> <aop:advisor pointcut-ref="servicePointcut" advice-ref="txAdvice" order="3" /> </aop:config> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="add*" /> <tx:method name="insert*" /> <tx:method name="remove*" /> <tx:method name="save*" /> <tx:method name="update*" /> <tx:method name="delete*" /> <tx:method name="cancel*" /> <tx:method name="trans*" /> <tx:method name="commit*" /> <tx:method name="submit*" /> <tx:method name="issue*" /> <tx:method name="accept*" /> <tx:method name="underwrite*" /> <tx:method name="modify*" /> <tx:method name="calculate*" /> <tx:method name="copy*" /> <tx:method name="print*" /> <tx:method name="create*" /> <tx:method name="send*" /> <tx:method name="activate*" /> <tx:method name="generate*" /> <tx:method name="do*" /> <tx:method name="find*" read-only="true" /> <tx:method name="get*" read-only="true" /> <tx:method name="load*" read-only="true" /> <tx:method name="list*" read-only="true" /> <!-- log方法会启动一个新事务 --> <tx:method name="log*" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" /> <!-- 如果通过java代码来进行分库判断,这里exeNewTS方法需要启动一个新事务 ,切换数据源时使用--> <tx:method name="exeNewTS*" propagation="REQUIRES_NEW" isolation="READ_COMMITTED" /> <!-- <tx:method name="exeNewTS*"/> --> </tx:attributes> </tx:advice>

转载于:https://www.cnblogs.com/xiao--y/p/6634556.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)