Question

I am facing the same issue as:

AspectJ load time weaving not working on Spring beans

The solution of returning 'Object' is working, but I don't know the reason.

I have gone through:

http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch08s08.html#aop-aj-ltw

but still no clue.

Was it helpful?

Solution

As I commented on that other thread.

The load-time weaver, as the name suggest, will only operate on the loading of classes. Now when a class is already loaded it cannot be processed anymore.

When the return type is the concrete class it will result in eagerly loading that class, it will be loaded before the load time weaver is registered and can do it stuff.

When the return type is Object the loading of the class is deferred until the class is actually needed and in general this will be after the load time weaver has been registered so it can do its work.

You can simply verify this behavior by adding -verbose:class as parameters when you run the program (like you would add properties). You then get an extensive list of classes when they get loaded.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top