I am working on a project that uses the Spring (not xml) Spring configuration adapter to connect dependencies. It also has profiling logic that must be compressed through AspectJ to the required methods (via annotations). The setup works, and I see how the classes from my desired package are woven and the profiling data comes out of them.
The problem is that weaving does not work for @Bean classes. I have included debug in aop.xml via:
<weaver options="-XnoInline -Xreweavable -verbose -debug -showWeaveInfo">
And I see that the classes in my desired package are woven, but not beans in the configuration. If I instantiate the classes directly (without pasting them), the weaving works.
Unfortunately, I cannot post the real code here, but here is an example:
@Configuration @EnableLoadTimeWeaving(aspectjWeaving = EnableLoadTimeWeaving.AspectJWeaving.ENABLED) public class MySpringConfig { @Bean AnnotatedClass1 annotatedClass1() { return new AnnotatedClass1(new AnnotatedClass2()); } }
AnnotatedClass1 and AnnotatedClass2 live in the same package, and the weaves runs on an instance created directly, and not the one returned by the bean.
I looked through Spring AOP docs , but I can not find anything related to this. There is some magic for automatic proxying and some limitations for SpringAOP, but the time taken to load should work as far as I can tell - for example, I tried to use private methods, and it worked.
java spring aop aspectj configuration
Alex ciminian
source share