3

I'm reading spring documentation about AOP and now I'm at the section about using @AspectJ style.

Spring AOP is implemented in pure Java. There is no need for a special compilation process. Spring AOP does not need to control the class loader hierarchy, and is thus suitable for use in a Servlet container or application server.

But in the section about @AspectJ style said

The @AspectJ support can be enabled with XML or Java style configuration. In either case you will also need to ensure that AspectJ’s aspectjweaver.jar library is on the classpath of your application (version 1.6.8 or later).

As far as I know, aspectjweaver.jar performs the actual weaving of aspects at compile-time or load time. But Spring has its own proxy-based implementation. So I really don't see any reason for aspectjweaver.jar dependency.

That's true, to use @Aspect annotation we need aspectjrt dependency. But the dependency on weaver is not clear to me. Couldn't you explain in a nutshell how it actually works?

  • 2
    Some related question: http://stackoverflow.com/questions/11446893/spring-aop-why-do-i-need-aspectjweaver – Aritz Feb 16 '16 at 08:50
  • 1
    That jar is needed as it contains classes which enable spring to parse the expressions. – M. Deinum Feb 16 '16 at 09:10

1 Answers1

1

Spring AOP doesn't use the AspectJ weaver itself, but it reuses some of the classes from the aspectjweaver.jar file. It is used to define AspectJ-style pointcut expression, e.g. @Before.

Christiaan Janssen
  • 1,003
  • 1
  • 9
  • 14