org.springframework.aop.interceptor
public class: ExposeInvocationInterceptor [javadoc |
source]
java.lang.Object
org.springframework.aop.interceptor.ExposeInvocationInterceptor
All Implemented Interfaces:
org.aopalliance.intercept.MethodInterceptor, Serializable
Interceptor that exposes the current
org.aopalliance.intercept.MethodInvocation
as a thread-local object. We occasionally need to do this; for example, when a pointcut
(e.g. an AspectJ expression pointcut) needs to know the full invocation context.
Don't use this interceptor unless this is really necessary. Target objects should
not normally know about Spring AOP, as this creates a dependency on Spring API.
Target objects should be plain POJOs as far as possible.
If used, this interceptor will normally be the first in the interceptor chain.
- author:
Rod - Johnson
- author:
Juergen - Hoeller
| Field Summary |
|---|
| public static final ExposeInvocationInterceptor | INSTANCE | Singleton instance of this class |
| public static final Advisor | ADVISOR | Singleton advisor for this class. Use in preference to INSTANCE when using
Spring AOP, as it prevents the need to create a new Advisor to wrap the instance. |
| Method from org.springframework.aop.interceptor.ExposeInvocationInterceptor Detail: |
public static MethodInvocation currentInvocation() throws IllegalStateException {
MethodInvocation mi = (MethodInvocation) invocation.get();
if (mi == null)
throw new IllegalStateException(
"No MethodInvocation found: Check that an AOP invocation is in progress, " +
"and that the ExposeInvocationInterceptor is in the interceptor chain.");
return mi;
}
Return the AOP Alliance MethodInvocation object associated with the current invocation. |
public Object invoke(MethodInvocation mi) throws Throwable {
Object old = invocation.get();
invocation.set(mi);
try {
return mi.proceed();
}
finally {
invocation.set(old);
}
}
|