according to javadoc http://www.springframework.org/docs/....lan g.String[])
The referenced beans should be of type Interceptor, Advisor or Advice The last entry in the list can be the name of any bean in the factory. If it's neither an Advice nor an Advisor, a new SingletonTargetSource is added to wrap it. Such a target bean cannot be used if the "target" or "targetSource" or "targetName" property is set, in which case the "interceptorNames" array must contain only Advice/Advisor bean names.
Code:
<bean id="invocationHandler" class="com.blah.ServiceInvocationHandlerClient" singleton="true">
<constructor-arg type="java.lang.Class" value="com.blah.Service" />
<constructor-arg type="com.blah.ClientDelegate">
<bean class="com.blah.ClientDelegate" />
</constructor-arg>
</bean>
<bean id="proxyLookupInterceptor" class="com.blah.ProxyCreationInterceptor">
<property name="invocationHandler" ref="invocationHandler" />
</bean>
<bean id="client" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames" value="proxyLookupInterceptor" />
<property name="proxyInterfaces" value="com.blah.Service" />
</bean>
As you can see, I specify an Interceptor in interceptorNames property, but no target ('cause I don't have one), in which case I expect a SingletonTargetSource would wrap my interceptor and become a target of this proxy, but this is not happening. When I inspect values of MethodInvocation in this ProxyCreationInterceptor:
Code:
public class ProxyCreationInterceptor<T> implements MethodInterceptor {
private Object cachedProxy;
private InvocationHandler invocationHandler;
public Object invoke(MethodInvocation mi) throws Throwable {
return mi.getMethod().invoke(
getProxy(mi.getThis().getClass(), mi.getThis()),
mi.getArguments());
}
public void setInvocationHandler(InvocationHandler ih) {
invocationHandler = ih;
}
private synchronized Object getProxy(Class clazz, Object target) {
if (cachedProxy == null) {
cachedProxy = Proxy.newProxyInstance(
clazz.getClassLoader(), new Class[]{clazz}, invocationHandler);
}
return cachedProxy;
}
}
mi.getThis() returns null, since this is what my ProxyFactoryBean ends up holding as its target.
Is this a bug? Any workarounds possible?