Search code examples
springaopaspectjload-time-weaving

Spring AOP with AspectJ: Load time weaving


If I'm using AspectJ based Spring AOP, am I then tied to configuring my aspects to use load time weaving? Or does Spring AOP also support run time/compile time weaving when using the AspectJ based approach?


Solution

  • Spring AOP is proxy based. Unless configured to do otherwise, Spring AOP performs run-time weaving.

    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.

    Source: http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#aop-introduction-defn


    You can however set up Spring to do load-time weaving. Check Spring documentation on how to do this: http://docs.spring.io/spring/docs/3.2.0.RELEASE/spring-framework-reference/htmlsingle/#aop-aj-ltw

    Among other things, you would be using @EnableLoadTimeWeaving in your Java Config class. The setup is fairly simple and your @Aspect classes would not change.

    Developers simply modify one or more files that form the application context to enable load-time weaving instead of relying on administrators who typically are in charge of the deployment configuration such as the launch script