java - Intercept static method with aspectJ -
this question has answer here:
i'm using spring , trying write sample application aspectj. need learn how intercept static method calls. in example i'm trying intercept main method 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 run application, str
string being printed.
you using dynamic proxy approach proxy object created @ runtime. proxy object uses inheritance proxying target methods. since can not inherit static method, approach wont work static methods.
for creating proxy static
methods need use aspectj's compile time weaving. can refer this link more info. this might help.
Comments
Post a Comment