aop and spring

aop是一种编程思想.springaspectj是这种思想的2种具体实现.

可以通过注解开启springaop功能(@EnableAspectJAutoProxy).

springaop实现,有2种形式,一种是通过运行期的动态代理实现,另外一种是委托给aspectj进行处理.

aspectj又有2种形式的实现,一种是编译期间的织入,一种是通过特殊的类加载器进行加载时的织入,即所说的ltw.spring中可以通过注解(@EnableLoadTimeWeaving)启用ltw.不过需要做一些配置:

  1. 引入spring-instrument作为新的类加载器,这个类加载器可以在加载类的时候把代理织入进去;
  2. 设置启动参数:-javaagent:C:\Users\Administrator\.m2\repository\org\springframework\spring-instrument\5.2.3.RELEASE\spring-instrument-5.2.3.RELEASE.jar.

具体功能是如何在spring中工作的,未完待续.