咱们花了不少篇幅讲解了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…