spring AOP 学习笔记
2011-05-21 22:51
288 查看
术语理解:
cross-cutting concerns:散落在业务中,但又与业务无关的代码片段。
|
|识别为Aspect
|
v
Aspect:通过整理cross-cutting concerns,需要从中识别出可重用的、功能单一的切面,例如日志/权限检查切面等。
|
|============分割线:上面是业务中的概念,下面是代码中的概念==========
|
|实现为Advisor(主要是PointcutAdvisor = Pointcut +Advise)
|
v
Pointcut:触发时机,即做的前提条件,通常需要target/client符合某些情况时才触发Advise。例如target的类名/方法名符合指定正则表达式时触发Advise。Pointcut支持取交集/并集。
+
Advise:触发内容,即做什么。例如日志动作/权限检查动作的具体实现。
|
|
|_ _ _ Joinpoint: Advise的属性,表明做什么的时刻,spring只能在以下情况中任选:target的方法前/后/环绕/抛出异常时。
Spring AOP的核心思想是代理:
client ----透明调用目标----> proxy ----织入目标----> target|
v
改变行为 / 增加行为
| |
v v
PointcutAdvisor IntroductionAdvisor
配置方式:
ProxyBean|
|
|_ _ _ proxyInterfaces:targetInterface
|
|
|_ _ _ target:targetBean
|
|
|_ _ _ interceptorNames:可以填入Advise/ Advisor/ Interceptor
直接填Advise即省略了Pointcut,表示proxyInterfaces中声明的所有方法都要触发Advise。Interceptor和Advisor类似,只不过前者是AOP Alliance制定的标准,后者是spring自己的标准。
PointcutAdvisor(以DefaultPointcutAdvisor为例)
|
|
|_ _ _ pointcut:pointcutBean
|
|
|_ _ _ advise:adviseBean
动态改变了targetInterface中描述的行为,在pointcutBean中指定了触发时机,在adviseBean中指定了触发内容。
IntroductionAdvisor(以DefaultIntroductionAdvisor为例)
|
|
|_ _ _ constructor-arg0:IntroductionBean
|
|
|_ _ _ constructor-arg1:IntroductionInterface
为target动态增加了IntroductionInterface中描述的行为,其具体实现在IntroductionBean中。
相关文章推荐
- Spring2.5学习笔记2-AOP-利用注解
- [Spring入门学习笔记][Spring的AOP原理]
- Spring-AOP配置(学习笔记)
- Spring学习笔记之SpringAOP基础
- Spring学习笔记(二)后处理器与AOP
- [Spring]面向切面编程AOP【学习笔记】
- JavaWeb学习笔记-spring-14-AOP-创建切面(静态正则表达式方法匹配切面)
- spring学习笔记: Spring AOP
- Spring2.5学习笔记2-AOP-利用通知接口
- Spring学习笔记(二)Spring基础AOP、IOC
- spring学习笔记6--简单模拟实现AOP(cglib版)
- [Spring入门学习笔记][Spring的AOP原理]
- spring学习笔记9--AOP表达式小例子
- 【spring学习笔记三】aop思想介绍及实现原理
- Java框架spring 学习笔记(十一):aop相关概念
- Spring学习笔记四(AOP中的通知参数和注解开发)
- 【Spring学习笔记】之【6.1 AOP之AOP基础】
- Spring 学习笔记(六)—— AOP的简单理解
- spring学习笔记(22)----基于配置文件的方式来配置AOP
- ITCAST视频-Spring学习笔记(使用Spring配置文件实现AOP)