AOP-Advisor-笔记
一、Advisor接口
这个接口是一个通知者的顶层接口。它实现类持有一个通知(advice)和一个过滤器的引用。用过滤器来决定通知是否合适目标对象。
这个接口只有两个方法,所以将整个代码贴上来。
/**
* Base interface holding AOP <b>advice</b> (action to take at a joinpoint)
* and a filter determining the applicability of the advice (such as
* a pointcut). <i>This interface is not for use by Spring users, but to
* allow for commonality in support for different types of advice.</i>
*
* <p>Spring AOP is based around <b>around advice</b> delivered via method
* <b>interception</b>, compliant with the AOP Alliance interception API.
* The Advisor interface allows support for different types of advice,
* such as <b>before</b> and <b>after</b> advice, which need not be
* implemented using interception.
*
* @author Rod Johnson
*/
public interface Advisor { /**
* Return the advice part of this aspect. An advice may be an
* interceptor, a before advice, a throws advice, etc.
* @return the advice that should apply if the pointcut matches
* @see org.aopalliance.intercept.MethodInterceptor
* @see BeforeAdvice
* @see ThrowsAdvice
* @see AfterReturningAdvice
*///返回切面中的一个通知,这个通知有可能是个拦截器。
Advice getAdvice(); /**
* Return whether this advice is associated with a particular instance
* (for example, creating a mixin) or shared with all instances of
* the advised class obtained from the same Spring bean factory.
* <p><b>Note that this method is not currently used by the framework.</b>
* Typical Advisor implementations always return {@code true}.
* Use singleton/prototype bean definitions or appropriate programmatic
* proxy creation to ensure that Advisors have the correct lifecycle model.
* @return whether this advice is associated with a particular target instance
*///返回一个通知是与一个实例关联还是的与多个实例关联,如果只与一个实例关联,那么就返回true.
boolean isPerInstance(); }
二、 Advisor的子接口PointcutAdvisor
这个接口几乎是所有通知者的父接口,除了引入通知者之外。可以在方法级别上判断通知是否适用。
/**
* Superinterface for all Advisors that are driven by a pointcut.
* This covers nearly all advisors except introduction advisors,
* for which method-level matching doesn't apply.
*
* @author Rod Johnson
*/
public interface PointcutAdvisor extends Advisor { /**
* Get the Pointcut that drives this advisor.
*/
Pointcut getPointcut(); }
三、AspectJPointcutAdvisor
一)、这个类的属性
这个类的属性很少,只有三个。分别是通知、切点、顺序。Advisor就是用来将通知和切点结合在一起的。
private final AbstractAspectJAdvice advice;//通知 private final Pointcut pointcut;//切点 private Integer order;//顺序,值越小优先级越高。如:值为1的优先级高于值为5的优先级。看Ordered接口。
二)、这个类的方法
这个类的方法也很简单,主要是一个构造方法,和若干个setter、getter方法,用来设置和获取以上的三个属性的。
①、构造方法
构造方法初始化通知和切点。
/**
* Create a new AspectJPointcutAdvisor for the given advice
* @param advice the AbstractAspectJAdvice to wrap
*/
public AspectJPointcutAdvisor(AbstractAspectJAdvice advice) {
Assert.notNull(advice, "Advice must not be null");
this.advice = advice;
this.pointcut = advice.buildSafePointcut();//
}
其他setter和getter方法就不列举了,可以想象的到。
所以现在如果提起Advisor,要能想象到这个Advisor具体是什么样子的。一个Advisor由通知、切点、顺序组成。
还有一个知识点,Advisor是什么实例化的?
根据的我的debug,发现它是在SpringIOC容器初始化或者刷新的时候初始化的。具体来说是在AbstractApplicationContext.refresh()方法中。因为Advisor都是非懒加载单例对象。
refresh()方法中的代码:
// Instantiate all remaining (non-lazy-init) singletons.
finishBeanFactoryInitialization(beanFactory);
就是上面这句代码执行了对Advisor的初始化。
AOP-Advisor-笔记的更多相关文章
- spring Aop中aop:advisor 与 aop:aspect的区别
转载:http://blog.csdn.net/u011710466/article/details/52888277 在spring的配置中,会用到这两个标签.那么他们的区别是什么呢? ...
- spring 中的<aop:advisor>和<aop:aspect>的区别
在AOP中有几个概念: — 方面(Aspect):一个关注点的模块化,这个关注点实现可能另外横切多个对象.事务管理是J2EE应用中一个很好的横切关注点例子.方面用Spring的Advisor或拦截器实 ...
- 关于spring aop Advisor排序问题
关于spring aop Advisor排序问题 当我们使用多个Advisor的时候有时候需要排序,这时候可以用注解org.springframework.core.annotation.Order或 ...
- <aop:aspect>与<aop:advisor>的区别
在开发过程中,不少有Spring Aop的使用,在面向切面编程时,我们会使用< aop:aspect>:在进行事务管理时,我们会使用< aop:advisor>.那么,对于&l ...
- Spring AOP学习笔记
Spring提供了一站式解决方案: 1) Spring Core spring的核心功能: IOC容器, 解决对象创建及依赖关系 2) Spring Web ...
- 利用cglib包实现Spring中aop的<aop:advisor>功能
一:前言 还有<aop:before>/<aop:after>/<aop:around>的没有实现,不过根<aop:advisor>是差不多的,就是要额 ...
- spring错误处理 Build path is incomplete. Cannot find class file for org.springframework.aop.Advisor
Build path is incomplete. Cannot find class file for org.springframework.aop.Advisor 初学spring,记录一下出现 ...
- hibernate事务配置Aop aop:advisor模式
<!-- 使用HibernateTransactionManager管理hibernate事务 --> <bean id="txManager" class=&q ...
- Spring入门IOC和AOP学习笔记
Spring入门IOC和AOP学习笔记 概述 Spring框架的核心有两个: Spring容器作为超级大工厂,负责管理.创建所有的Java对象,这些Java对象被称为Bean. Spring容器管理容 ...
- AOP 学习笔记
代理是一个设计模式,提供了对目标对象另外的访问方式:即通过代理访问目标对象. 好处:可以在目标对象实现的基础上,增强额外的功能操作. Cglib 代理,也叫作 子类代理. JDK的动态代理有一个限制, ...
随机推荐
- [转]浅谈 JavaScript的原型对象与原型链
看到这篇文章写的很好,转过来以便今后阅读. 原文地址:http://www.cnblogs.com/shuiyi/p/5305435.html 对于新人来说,JavaScript的原型是一个很让人头疼 ...
- [javascript] Promise简单学习使用
原文地址:http://www.cnblogs.com/dojo-lzz/p/4340897.html 解决回调函数嵌套太深,并行逻辑必须串行执行,一个Promise代表一个异步操作的最终结果,跟Pr ...
- C# 实现寻峰算法的简单优化(包含边峰,最小峰值,峰距)
核心寻峰算法的原理参考Ronny,链接:投影曲线的波峰查找, C#翻译原理代码参考sowhat4999,链接:C#翻译Matlab中findpeaks方法 前人种树,后人乘凉.感谢原作者详细的解释 ...
- hdu 1023 卡特兰数《 大数》java
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- fzu 2155 盟国
Problem 2155 盟国 Accept: 39 Submit: 129Time Limit: 1000 mSec Memory Limit : 32768 KB Problem De ...
- PHP错误日志和内存查看
1.通过命令查看服务器上一共开了多少的 php-cgi 进程: ps -fe |grep "php-fpm"|grep "pool"|wc -l 2.查看FPM ...
- git使用总结(常用命令)
前言 写这篇文章的目的是让新手能够操作git管理自己的代码,可能你知道git的各种命令但是对其使用顺序并不熟,比如我.所以有必要整合一篇关于命令使用步骤的文章,图片用的人家的,也没询问让不让用,可能会 ...
- [移动端WEB] 移动端input标签按钮为什么在苹果手机上还有一层白色?
移动端input标签按钮为什么在苹果手机上还有一层白色? 解决办法:其实蛮简单的,就加一个属性就好了 input { outline:0px ; -webkit-appearance: none; } ...
- apply的“非改变this“的用法
说到apply,大家都是知道是改变this指向的,也都会立马和call联系在一起,MDN官网上也是如是说: 其实我们在平常使用call和apply的时候,都是想到他们的改变函数的this的功能, 正如 ...
- html打造动画【系列2】- 可爱的蛙蛙表情
先感受一下全部表情包: 在开始之前先安利一个知识点:Flex弹性布局 我们一般做水平三列布局都是用的float方法,将每一块浮动显示在同一行.这种方法会导致元素没有原来的高度属性,要用清除浮动来解决空 ...