咱們花了不少篇幅講解了Spring AOP的實現原理動態代理,可是隻有動態代理是不夠的,好比說前面提到的Aspect、Join Point、Pointcut等,這些有關AOP的抽象概念也很是重要,咱們知道這部分其實是由AspectJ提供的,那麼AspectJ是什麼呢?html
aspectj isgit
AspectJ都包括了哪些內容?github
或許有人要問,既然AspectJ是須要編譯的,那麼Spring AOP怎麼沒有使用額外的編譯工具呢?spring
那是由於Spring僅使用了AspectJ的模型和語言表達式部分。app
AspectJ的相關內容很是多,幾篇文章都不必定能說的完,這塊不是咱們討論的重點,有興趣的同窗請參考附錄資料。框架
在解讀源碼以前,咱們先看下Spring AOP的官方文檔,從中咱們能獲取到極爲重要的信息。less
Spring 提供了schema和@AspectJ註解兩種風格,這兩種風格本質上使用的都是AspectJ提供的切入點語言。eclipse
在Spring AOP的織入特性中,咱們得知Spring AOP僅支持runtime織入,而AspectJ支持compile time,load time,runtime三種.ide
Spring AOP currently supports only method execution join points (advising the execution of methods on Spring beans). Field interception is not implemented, although support for field interception could be added without breaking the core Spring AOP APIs. If you need to advise field access and update join points, consider a language such as AspectJ.工具
Spring AOP never strives to compete with AspectJ to provide a comprehensive AOP solution. We believe that both proxy-based frameworks such as Spring AOP and full-blown frameworks such as AspectJ are valuable and that they are complementary, rather than in competition.
上面這段內容主要提到了,Spring AOP僅支持method接入點,不支持field接入點;Spring AOP的目標歷來都不是提供完整的AOP解決方案,Spring AOP和AspectJ更像是互補的關係,而不是競爭關係.
Spring AOP defaults to using standard JDK dynamic proxies for AOP proxies. This enables any interface (or set of interfaces) to be proxied. Spring AOP can also use CGLIB proxies. This is necessary to proxy classes rather than interfaces. By default, CGLIB is used if a business object does not implement an interface
Spring AOP默認使用JDK動態代理,同時也支持CGLIB,當代理類而不是接口的時候,默認使用CGLIB方式.
從官方文檔中咱們可以得出來如下重要信息:
AspectJ:www.eclipse.org/aspectj/doc…
cglib:github.com/cglib/cglib
Spring AOP:docs.spring.io/spring/docs…
Spring Source Code:github.com/spring-proj…