I'm using Spring and trying to write my sample application with AspectJ. I need to learn how to intercept static method calls. In my example I'm trying to intercept the main method as follows:
Spring configuration file:
<aop:aspectj-autoproxy />
<!-- Aspect -->
<bean id="logAspect" class="com.package.Aspect" />
The main method:
public class App {
public static void main(String[] args) throws Exception {
ApplicationContext appContext = new ClassPathXmlApplicationContext("Spring-Customer.xml");
System.out.println("str");
}
}
The asspect itself:
@Aspect
public class Aspect {
@Around("execution(*App.main(..))")
public void logAround(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("Intercepted!");
}
}
But when I run the application, the only str
string is being printed.