Some summary notes of SpringAOP

Some term meanings of Spring AOP

Summary of Spring AOP

  1. Spring AOP is divided into JDK implementation and CGLib implementation. Although Spring AOP uses the AspectJ package, it is just that Spring borrows AspectJ annotations to achieve pointcut parsing and matching, which means that AspectJ will only be used when annotating programming. AspectJ is also a framework for implementing aspect programming (AOP), and has its own compiler.
    Spring official website original explanation:

Spring interprets the same annotations as AspectJ 5, using a library supplied by AspectJ for pointcut parsing and matching. The AOP runtime is still pure Spring AOP, though, and there is no dependency on the AspectJ compiler or weaver.

  1. By default Spring implements Spring AOP using JDK dynamic proxies.
    The reasons are as follows (excerpted from Spring official website):

By default, CGLIB is used if a business object does not implement an interface. As it is good practice to program to interfaces rather than classes, business classes normally implement one or more business interfaces.

If you want to enable CGlib, you can add the configuration in xml:

<aop:aspectj-autoproxy proxy-target-class="true"/>
<!--默认是false-->
  1. Some features of CGLib:
  • Classes that use CGLib proxy do not need to implement interfaces, because CGlib directly inherits the proxy implemented by that class, which also means that the final keyword will invalidate the proxy or even report an error

Supongo que te gusta

Origin blog.csdn.net/weixin_55658418/article/details/127601071
Recomendado
Clasificación