1

在使用 AopAlliance 进行方法拦截时,有没有办法从被拦截的类中调用方法?

例如:

public class MyClass {
     public void interceptMe() {}
     public void invokeMe() {}
}

public class MyInterceptor implements MethodInterceptor {
     public Object invoke(MethodInvocation invocation) throws Throwable {
          // This is where MyClass.interceptMe() is intercepted
          // I would like to call MyClass.invokeMe() for the instance of the class who's method was intercepted
     }
}

如果需要,我很乐意提供更多详细信息。

4

1 回答 1

2

怎么样

((MyClass)invocation.getThis()).invokeMe()

http://aopalliance.sourceforge.net/doc/org/aopalliance/intercept/MethodInvocation.html

于 2011-05-24T04:57:09.600 回答