I need to capture private inner calling methods.
So, I need to use aspectj weaving into my spring-boot project:
@Configuration
@EnableAspectJAutoProxy
public class ApiConfiguration implements WebMvcConfigurer { /*...*/ }
I need to capture a @Service
private method execution:
package net.space.service;
// imports
@Service
public class RepositoryService {
private void privateMethod(String param) {
/* Do something */
}
public void innerCaller() {
this.privateMethod(null);
}
}
IMPORTANT: privateMethod
is private and is called only by innerCaller
.
However, advice is never reached. How could I solve that?
I've also tried with this pointcut:
@Pointcut(value = "execution(* privateMethod(..))")
public void privatePointcut() {
}
and advice:
@AfterReturning("privatePointcut()")
public void groupMetrics(JoinPoint point) throws Throwable {
// Do something
}
I've also tried with:
@Pointcut(value = "execution(* net.space.service.RepositoryService.privateMethod(..))")
@Pointcut(value = "execution(* RepositoryService.privateMethod(..))")
EDIT
I've also tried to use @EnableLoadTimeWeaving
:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loadTimeWeaver' defined in class path resource [org/springframework/context/annotation/LoadTimeWeavingConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.instrument.classloading.LoadTimeWeaver]: Factory method 'loadTimeWeaver' threw exception; nested exception is java.lang.IllegalStateException: ClassLoader [sun.misc.Launcher$AppClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590) ~[spring-beans-5.0.8.RELEASE.jar:5.0.8.RELEASE]