AspectJ profile

We’ve spent a lot of time talking about Spring AOP’s implementation principles, dynamic proxies, but dynamic proxies alone are not enough. Aspects, Join points, Pointcut, and other AOP abstractions are also important. We know that this part is actually provided by AspectJ, so what is AspectJ?

aspectj is

  • a seamless aspect-oriented extension to the Javatm programming language
  • Java platform compatible
  • easy to learn and use

What does AspectJ include?

  • Provides section-oriented models such as aspects, pointcuts, and so on
  • It has its own complete language architecture, similar to execution(** com.aop.biz)..(..) ) expression of this kind
  • Have their own set of development and compilation tools
  • AOP is also essentially present through access to bytecode

One might ask, since AspectJ is compiled, why doesn’t Spring AOP use additional compilation tools?

That’s because Spring uses only the model and language expression parts of AspectJ.

AspectJ covers more than a few articles. This is not the focus of our discussion, so please refer to the appendix if you are interested.

Spring AOP official documentation interpretation

Before diving into the source code, let’s take a look at the official Spring AOP documentation, where we can glean extremely important information.

Spring provides simple and powerful ways of writing custom aspects by using either a schema-based approach or the @AspectJ annotation style. Both of these styles offer fully typed advice and use of the AspectJ pointcut language while still using Spring AOP for weaving.

Spring provides schema and @AspectJ annotation styles, both of which essentially use the pointcut language provided by AspectJ.

Weaving: linking aspects with other application types or objects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), load time, or at runtime. Spring AOP, like other pure Java AOP frameworks, performs weaving at runtime

Spring AOP only supports runtime weaving, while AspectJ supports compile Time, load time, and Runtime weaving.

Spring AOP Capabilities and Goals

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 only supports method access points and does not support field access points. The goal of Spring AOP has never been to provide a complete AOP solution, and Spring AOP and AspectJ are more complementary than competitive.

AOP Porxies

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 uses JDK dynamic proxies by default and also supports CGLIB, which is used by default when proxying classes rather than interfaces.

From the official documents we can draw the following important information:

  • Spring AOP is a pure Java AOP framework
  • Spring AOP is a proxy-based AOP framework
  • Spring AOP is not a complete AOP implementation; it primarily provides a seamless integration between AOP and IoC
  • Spring AOP’s Pointcut uses AspectJ’s language
  • Spring AOP only supports runtime weaving, not compile time and load time
  • Spring AOP only supports join points executed by method, not field
  • Spring AOP supports both JDK Proxy and CGLIB, using JDK Proxy for proxy interfaces and CGLIB for proxy classes

Reference data

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…