Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring AOP - why do i need aspectjweaver?

i wrote a very simple Aspect with Spring AOP. It works, but i have some problems understanding what is really going on. I don't understand why i have to add the aspectjweaver.jar? The Spring-AOP documentation clearly states that i don't need aspectj compiler or weaver as long as i just use Spring-AOP:

The AOP runtime is still pure Spring AOP though, and there is no dependency on the AspectJ compiler or weaver.

My configuration looks like this:

<aop:aspectj-autoproxy />  @Aspect @Service public class RemoteInvocationAspect {      @Before("execution(* at.test.mypackage.*.*(..))")     public void test() {         System.out.println("test");     }     ... 

I also tried XML configuration, didn't change anything though. Maybe i could just let it go, but i really would like to understand why aspectj-weaver is used? If i don't add the dependency in maven i get java.lang.ClassNotFoundException: org.aspectj.weaver.reflect.ReflectionWorld$ReflectionWorldException

like image 703
Mario B Avatar asked Jul 12 '12 07:07

Mario B


People also ask

What is the use of Aspectjweaver?

The AspectJ weaver applies aspects to Java classes. It can be used as a Java agent in order to apply load-time weaving (LTW) during class-loading and also contains the AspectJ runtime classes.

Why do we need Spring AOP?

Aspect-oriented programming (AOP) is one of the major components of the Spring Framework. The Spring AOP helps in breaking down the logic of the program into several distinct parts called as concerns. Cross-cutting concerns is the functions which span multiple points of an application.

What is Aspectjweaver jar?

aspectjweaver. jar is an AspectJ library needed for LTW (load-time weaving), as opposed to compile-time weaving.


1 Answers

Spring AOP implementation I think is reusing some classes from the aspectj-weaver. It still uses dynamic proxies - doesn't do byte code modification.

The following comment from the spring forum might clarify.

Spring isn't using the AspectJ weaver in this case. It is simply reusing some of the classes from aspectjweaver.jar.

-Ramnivas

like image 197
gkamal Avatar answered Oct 08 '22 10:10

gkamal