UDN-企业互联网技术人气社区

板块导航

浏览  : 878
回复  : 3

[框架] 手把手教你写个AOP框架

[复制链接]
一只小老鼠的头像 楼主
发表于 2015-6-16 16:45:05 | 显示全部楼层 |阅读模式
本帖最后由 一只小老鼠 于 2015-6-18 14:09 编辑

  Why AOP?

  AOP(Aspect-OrientedProgramming),意思是面向切面编程。传统的OOP面向对象相当于站在一个上帝模式从上往下看,里面的一块块都是一个对象,由我任意组合;而AOP不同之处在于,他是以一个旁观者的身法,从“侧面”看整个系统模块,看看哪里可以见缝插针,将自己想要处理的一段业务逻辑“编织”进去。

  Codeduplicationistheultimatecodesmell.It’sasignthatsomethingisverywrongwithimplementationordesign.(重复的代码会让代码的质量很糟糕。如果出现这个状况,那么一定是实现或者设计环境出了问题)

  OOP本身是极力反对“重复发明轮子”的,但是有时却对重复的代码显得无可奈何,而AOP本身是一种很好的能解决这个问题的一种思想。

  抽象了半天,还是利用一个例子还更加形象的解释吧。如果你要做一个权限系统,那么肯定需要在很多业务逻辑之前都加上一个权限判断——只有符合条件的才能完成后面的操作。如果利用传统思想,很显然你会把做权限判断的业务逻辑做封装,然后在每个业务逻辑执行之前都执行以下那片处理权限判断的代码。如下图:
204131_yitw_1378920.png
  看到没,每次一个判断每次一个判断,如果让这些权限判断的代码散落在系统的各个角落,那会是一个噩梦!就算采用OOP思想,将权限检查的业务放在一个类中,照样无济于事。因为每段业务代码开头总有这么一段抹不掉的身影(doSecurityCheck)。

  这时,AOP老兄终于按耐不住,要出场大展身手了!这位老兄马上说,放着那段业务逻辑代码,我来处理!

  他首先将权限处理的部分视作一个aspect(切面),然后想办法在运行时把切面weave(编织)进业务逻辑中合适的位置。比如就像这样做:
2.png
  这样,AOP就成功的帮我把权限验证部分插入到调用代码的前面执行。具体调用哪个方法其实AOP并不知道,只要你把切面织入了用户登录,那后调用用户登录,只要你织入了用户查询,那就调用用户查询。而且不单单是只掉某一个方法,它可以挨着排的调用。

  这只是其中一个强大的用处,还有像日志记录、性能分析、事务处理等更多都可以利用到AOP的地方。

  ThinkofAOPascomplementing,notcompetingwith,OOP.AOPcansupplementOOPwhereitisweak.(AOP和OOP没有竞争关系,相反,AOP能够很好的补充OOP的不足)

  AOP基本术语

  lAspect(切面):就是你想给程序织入的代码片段、如权限处理、日志记录等。

  lWeaving(编织):就是给指定的程序加上额外的业务逻辑的过程,比如将权限验证插入到用户登录的过程。

  lAdvice(通知):表示是在程序的哪里织入切面,比如前面织入,还是后面织入,或者是抛出异常的时候织入。

  lJoinpoint(连接点):表示给那个程序织入切面,也就是被代理的目标对象的目标方法。

  lPointcut(切入点):表示给哪些程序织入切面,是连接点的集合,比如是用户登录和用户查询等都需要被织入。

  为了方便用户使用AOP,需要定义几种通知类型。

  lBefore:前置通知,在业务逻辑之前通知

  lAfter:后置通知,在业务逻辑正常完结之后通知

  lEnd:结束通知,不管业务逻辑是否正常完结,都会在后面执行的通知

  lError:错误通知,在业务逻辑抛出异常的时候通知

  AOP执行流程

  下图展示了AOP核心调用过程,通过调用AOP代理类,开始一个一个调用后面的(前置)通知/拦截器链条,完成之后在调用目标方法,最后回来的时候接着调用(后置、结束)通知/拦截器链条。
3.png

  如此一来就成功的完成了在AOP中给某个程序(目标方法)之前加上一段业务逻辑,之后加上一段业务逻辑的流程,并且杀伤力极大,可以将目标方法的范围进行任意控制。

  动手实现一个AOP

  前戏那么长,高潮不会短!这次写的AOP参考了很多Spring的代码,吸收了大师补充的养分。

  利用测试驱动开发的原则,我们先来考虑考虑我们会怎么用(写好测试代码),然后想想API怎么设计(将接口写好),最后考虑实现的问题。

  1. <div class="line number1 index0 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Component</code></div><div class="line number2 index1 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Match</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">(methodMatch = </code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"org.*.doSomething"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">)</code></div><div class="line number3 index2 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">class</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">TransactionAspect </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">implements</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Before, End, Error {</code></div><div class="line number4 index3 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number5 index4 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Override</code></div><div class="line number6 index5 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">void</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">error(Method method, Object[] args, Exception e) {</code></div><div class="line number7 index6 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">System.out.println(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"回滚事务"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number8 index7 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number9 index8 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number10 index9 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Override</code></div><div class="line number11 index10 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">void</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">before(Method method, Object[] args) {</code></div><div class="line number12 index11 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">System.out.println(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"开启事务"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number13 index12 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number14 index13 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number15 index14 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Override</code></div><div class="line number16 index15 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">void</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">end(Method method, Object[] args, Object retVal) {</code></div><div class="line number17 index16 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">System.out.println(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"关闭事务"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number18 index17 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number19 index18 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number20 index19 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><p>  @Component</p><p>
  2. </p><p>  @Match(methodMatch="org.*.doSomething")</p><p>
  3. </p><p>  publicclassTransactionAspectimplementsBefore,End,Error{</p><p>
  4. </p><p>  @Override</p><p>
  5. </p><p>  publicvoiderror(Methodmethod,Object[]args,Exceptione){</p><p>
  6. </p><p>  System.out.println("回滚事务");</p><p>
  7. </p><p>  }</p><p>
  8. </p><p>  @Override</p><p>
  9. </p><p>  publicvoidbefore(Methodmethod,Object[]args){</p><p>
  10. </p><p>  System.out.println("开启事务");</p><p>
  11. </p><p>  }</p><p></p>
复制代码


  1. <table border="0" cellpadding="0" cellspacing="0" style="width: 687px; font-size: 13px; color: rgb(51, 51, 51); widows: auto; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; box-sizing: content-box !important; min-height: inherit !important; background-image: none !important;"><tbody style="border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;"></tbody></table>
复制代码

    在代理工厂中,我们使用Objecttarget存储这个目标对象,并使用集合来记录所有该类涉及到的通知。
[size=1em]1

[size=1em]2

[size=1em]3

[size=1em]4

[size=1em]5

[size=1em]6

[size=1em]7

[size=1em]8

[size=1em]9

[size=1em]10

[size=1em]11

[size=1em]12

[size=1em]13

[size=1em]14

[size=1em]15

[size=1em]16

[size=1em]17

[size=1em]18

[size=1em]19

[size=1em]20

[size=1em]21

[size=1em][size=1em]   
  1. <div class="line number1 index0 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">private</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Object target;</code></div><div class="line number2 index1 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number3 index2 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">private</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">List<Advice> adviceList = </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">ArrayList<Advice>();</code></div><div class="line number4 index3 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number5 index4 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">/**</code></div><div class="line number6 index5 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* </code></div><div class="line number7 index6 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* @Title: setTarget</code></div><div class="line number8 index7 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* @Description: 设置目标</code></div><div class="line number9 index8 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* @param @param target 设定文件</code></div><div class="line number10 index9 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* @return void 返回类型</code></div><div class="line number11 index10 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">* @throws</code></div><div class="line number12 index11 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">     </code><code class="java preprocessor" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">*/</code></div><div class="line number13 index12 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">void</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">setTarget(Object target) {</code></div><div class="line number14 index13 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">this</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">.target = target;</code></div><div class="line number15 index14 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number16 index15 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number17 index16 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">void</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">addAdvice(Advice advice) {</code></div><div class="line number18 index17 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">if</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">(advice == </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">null</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">)</code></div><div class="line number19 index18 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">throw</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">NullPointerException(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"添加的通知不能为空"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number20 index19 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">adviceList.add(advice);</code></div><div class="line number21 index20 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">
  2. </code></div>
复制代码


  而在完成配置代理工厂后,需要通过这个代理工厂来获取代理对象。在获取代理对象之前,我们把之前完成的配置(目标方法、通知集合)都初始化到AdvisedSupport对象中,将这个对象整体传给后面的代理实现(jdk、cglib)完成代理类的初始化,以及通知和目标方法的调用。



  1. <div class="line number1 index0 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">   </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Object getProxy() {</code></div><div class="line number2 index1 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">if</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">(target == </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">null</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">)</code></div><div class="line number3 index2 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">throw</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">NullPointerException(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"目标对象不能为空"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number4 index3 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code> </div><div class="line number5 index4 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">AdvisedSupport config=</code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">AdvisedSupport(target, adviceList);</code></div><div class="line number6 index5 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number7 index6 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">AopProxy proxy = </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">null</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">;</code></div><div class="line number8 index7 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java comments" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 130, 0) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">// 若该目标对象实现了接口,就优先选择jdk动态代理;如果没有实现任何接口,就只能采用cglib动态代理;</code></div><div class="line number9 index8 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">if</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">(config.hasInterfaces()) {</code></div><div class="line number10 index9 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">logger.info(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"采用jdk动态代理"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number11 index10 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">proxy = </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">JDKAopProxy(config);</code></div><div class="line number12 index11 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">} </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">else</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">{</code></div><div class="line number13 index12 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">logger.info(</code><code class="java string" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: blue !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">"采用cglib动态代理"</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number14 index13 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">proxy = </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">CglibAopProxy(config);</code></div><div class="line number15 index14 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number16 index15 alt1" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">return</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">proxy.getProxy();</code></div><div class="line number17 index16 alt2" style="padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div>
复制代码

[size=1em]


  这里我们会根据不同的情况来判断他是选择jdk动态代理还是选择cglib动态代理。

  这里以jdk动态代理为例,cglib留给读者自行分析:

  1. <p> <code class="java keyword" style="white-space: pre; widows: auto; word-break: break-all; font-size: 1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; min-height: inherit !important; background-image: none !important;">public</code><span style="color: rgb(51, 51, 51); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; line-height: 13.75px; white-space: pre; widows: auto;"> </span><code class="java keyword" style="white-space: pre; widows: auto; word-break: break-all; font-size: 1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; min-height: inherit !important; background-image: none !important;">class</code><span style="color: rgb(51, 51, 51); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; line-height: 13.75px; white-space: pre; widows: auto;"> </span><code class="java plain" style="white-space: pre; widows: auto; word-break: break-all; font-size: 1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; background-image: none !important;">JDKAopProxy </code><code class="java keyword" style="white-space: pre; widows: auto; word-break: break-all; font-size: 1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; min-height: inherit !important; background-image: none !important;">implements</code><span style="color: rgb(51, 51, 51); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; line-height: 13.75px; white-space: pre; widows: auto;"> </span><code class="java plain" style="white-space: pre; widows: auto; word-break: break-all; font-size: 1em !important; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; background-image: none !important;">AopProxy, InvocationHandler {</code></p><div class="line number2 index1 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number3 index2 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">private</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">AdvisedSupport config;</code></div><div class="line number4 index3 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number5 index4 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">JDKAopProxy(AdvisedSupport config) {</code></div><div class="line number6 index5 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">this</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">.config = config;</code></div><div class="line number7 index6 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number8 index7 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number9 index8 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Override</code></div><div class="line number10 index9 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Object getProxy() {</code></div><div class="line number11 index10 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">return</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Proxy.newProxyInstance(config.getClassLoader(),</code></div><div class="line number12 index11 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">                </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">config.getInterfaces(), </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">this</code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">);</code></div><div class="line number13 index12 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number14 index13 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number15 index14 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java color1" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: grey !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">@Override</code></div><div class="line number16 index15 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">public</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Object invoke(Object proxy, Method method, Object[] args)</code></div><div class="line number17 index16 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">            </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">throws</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">Throwable {</code></div><div class="line number18 index17 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">        </code><code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">return</code> <code class="java keyword" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: rgb(0, 102, 153) !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">new</code> <code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">ReflectiveMethodInvocation(config.getInterceptors(),config.getMatchers(), args,</code></div><div class="line number19 index18 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">                </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">method, config.getTarget()).proceed();</code></div><div class="line number20 index19 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java spaces" style="word-break: break-all; color: rgb(64, 170, 83); font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">    </code><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><div class="line number21 index20 alt2" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"> </div><div class="line number22 index21 alt1" style="line-height: 13.75px; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; font-size: 13px; color: rgb(51, 51, 51); widows: auto; padding-right: 1em !important; padding-left: 1em !important; border-radius: 0px !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important; white-space: pre !important; background-image: none !important;"><code class="java plain" style="word-break: break-all; font-family: Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important; border: 0px !important; border-radius: 0px !important; color: black !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; line-height: 1.1em !important; outline: 0px !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-size: 1em !important; min-height: inherit !important; background-image: none !important;">}</code></div><p>  </p>
复制代码


  这里我们首先在getProxy初始化了代理类,然后当代理类的方法被调用时,会完成目标方法调用,这个步骤都是ReflectiveMethodInvocation对象完成的。这个类实现了MethodInvocation,目的是为了完成之后的回调过程,这个后面可以看到。在这个ReflectiveMethodInvocation类里面,我们存储了足够多的信息

  /**

  *通知advice

  */

  privateList<MethodInterceptor>chain;

  /**

  *每个advice所配置的匹配信息

  */

  privateList<Matcher>matches;

  /**

  *执行目标方法需要的参数

  */

  privateObject[]arguments;

  /**

  *目标方法

  */

  privateMethodmethod;

  /**

  *目标对象

  */

  privateObjecttarget;

  /**

  *记录当前advice链条(chain)所需要执行的方法的索引

  */

  privateintindex;

  目的很简单:就是将多个通知链条和目标对象的方法本身的调用整合起来,形成逻辑完善的链条——前置通知在目标方法前面排着队完成,如果目标方法抛出了异常就执行错误通知,一旦正常执行完成目标方法就执行后置通知,而结束通知时不管是是正常执行完目标方法还是抛出了异常,最后都会执行的一个通知。

  下面来看看这个类中处理一连串方法调用的核心方法proceed():

  @Override

  publicObjectproceed()throwsThrowable{

  //当链条走完的时候调用目标方法

  if(index==chain.size())

  returninvokeJoinpoint();

  Matchermatcher=matches.get(index);

  //查看是否匹配,

  if(matcher.matches(this.method,this.target.getClass())){

  returnchain.get(index++).invoke(this);

  }else{

  index++;

  returnproceed();

  }

  }

  /**

  *

  *@Title:invokeJoinpoint

  *@Description:调用连接点方法

  *@param@return

  *@param@throwsThrowable设定文件

  *@returnObject返回类型

  *@throws

  */

  protectedObjectinvokeJoinpoint()throwsThrowable{

  returnmethod.invoke(target,arguments);

  }

  很简单,就是当链条走完的时候,调用目标方法。否则就继续指向链条上的方法。这里有一个检测是否匹配的过程,也就是我给我的切面类,也就是处理事务的切面TransactionAspect配置了一个注解Match,这个注解表示当目标类是org包下的某个类时,我就会对他的doSomething方法完成拦截,在这个方法周围加上事务处理。


  @Component

  @Match(methodMatch="org.*.doSomething")

  publicclassTransactionAspectimplementsBefore,End,Error{

  @Override

  publicvoiderror(Methodmethod,Object[]args,Exceptione){

  System.out.println("回滚事务");

  }

  @Override

  publicvoidbefore(Methodmethod,Object[]args){

  System.out.println("开启事务");

  }

  @Override

  publicvoidend(Methodmethod,Object[]args,ObjectretVal){

  System.out.println("关闭事务");

  }

  }

  具体判断是否匹配,我采用的是正则表达式,也就是当目标类的某个方法被调用时,一旦检测到他符合methodMatch配置的正则表达式,就给该方法前后加上指定的逻辑。如果发现不匹配,这继续寻找链条上下一个通知,直到走完整个通知链条。

  这里大家肯定会有一个问题:在链条上获取到一个通知,执行该通知的时候,如何确保前置通知是再前面执行,后置通知是再后面执行呢?并且在完成调用之后确保执行后面的通知调用流程?

  其实,spring在这里用到了一个很巧妙的编程技巧——通过多态原理和回调函数来处理。


  chain.get(index++).invoke(this);

  这里获取到了第index个通知,拿到的是个接口类型,但是实现类出卖了他的本质,表示它到底是前置还是后置或者是其他等。当执行invoke时,将该MethodInvocation的实现类ReflectiveMethodInvocation的对象的引用传递进去。如此调用的方法,其实是这样的:

  可以发现,当实现类是后置通知的时候,我会选择AfterInterceptor来执行,当时前置通知的时候,会选择BeforeInterceptor来执行。也就是,碰到合适的通知,就采用合适的拦截器处理。

  以前置通知的方法拦截器为例:


  publicclassBeforeInterceptorimplementsMethodInterceptor{

  privateBeforeadvice;

  publicBeforeInterceptor(Beforeadvice){

  this.advice=advice;

  }

  @Override

  publicObjectinvoke(MethodInvocationmi)throwsThrowable{

  advice.before(mi.getMethod(),mi.getArguments());

  returnmi.proceed();

  }

  }

  看到这里是不是有种似曾相识的感觉,这不就是开始那个权限验证的翻版么?对啊,itis。这里实现的很明确,就是在目标方法调用之前执行before中的业务逻辑,接着进行mi.proceed()又回调到了我们MethodInvocation的实现类ReflectiveMethodInvocation中的proceed方法中了。

  这样,也就保证了链条的次序执行。

  来看看我们测试用例的输出结果吧:

  开启事务

  和哈哈哈哈哈...

  关闭事务

  目前还没能把ioc和aop整合起来使用,还有像ioc在webmvc框架中如何使用都还没提到,不过这些会在我们以后的博客中不断出现。

  源代码

  最后,放出源代码:https://github.com/mjaow/my_spring

转载自开源中国 jonath_lode的博客

4.png
发表于 2015-6-16 17:41:28 | 显示全部楼层
抱歉可能是我们论坛的问题,导致您的代码中出现了乱码,我们会向开发反馈的。
点评 ( 1 ) 收起 / 展开点评

祭司 2015年07月08日 10:53 详情 回复

想看这个帖子。。希望斑竹快速解决乱码问题

使用道具 举报

回复

发表于 2015-7-8 10:53:44 | 显示全部楼层
厨子右边卫 发表于 2015-6-16 17:41
抱歉可能是我们论坛的问题,导致您的代码中出现了乱码,我们会向开发反馈的。 ...

想看这个帖子。。希望斑竹快速解决乱码问题
使用道具 举报

回复

发表于 2015-7-8 10:54:12 | 显示全部楼层
楼主,这里有乱码,这篇文章别处还能看么,求地址
使用道具 举报

回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们
联系我们
  • 电话:010-86393388
  • 邮件:udn@yonyou.com
  • 地址:北京市海淀区北清路68号
移动客户端下载
关注我们
  • 微信公众号:yonyouudn
  • 扫描右侧二维码关注我们
  • 专注企业互联网的技术社区
版权所有:用友网络科技股份有限公司82041 京ICP备05007539号-11 京公网网备安1101080209224 Powered by Discuz!
快速回复 返回列表 返回顶部