PDA

View Full Version : how to add interceptor to mixin class


kalfen
Oct 29th, 2004, 11:36 AM
I have use BeanNameAutoProxyCreator to generate mixin proxy class, but how can I add interceptor to this class? Rod can you help me?

kalfen
Oct 30th, 2004, 12:29 PM
any body can help me? it's so urgent problem.
and for example this is the my sample code from spring test suite

<bean id="introductionBeanNameProxyCreator" class="org.springframework.aop.framework.autoproxy
<property name="beanNames"><value>*testbean</value></property>
<property name="interceptorNames">
<list>
<value>lockableAdvisor</value>
</list>
</property>
</bean>

<bean id="lockableAdvisor"
class="org.springframework.aop.framework.LockMixinAdvisor"
singleton="false"
>
</bean>

<bean id="testbean" class="org.springframework.beans.TestBean">
</bean>

public Class TestBean
{
public void doSomething(){
}
}

So I want a interceptor to intercept when doSomthing() method in the testbean is called,
this is part of interceptor code
Object invoke(methodInvocation invocation){
LockMixin mixin = (LockMixin)invocaton.getThis();
......
}
this show ClassCast error, why?

Rod Johnson
Nov 1st, 2004, 04:37 AM
Object invoke(methodInvocation invocation){
LockMixin mixin = (LockMixin)invocaton.getThis();
......
}
this show ClassCast error, why?
MethodInvocation.getThis() returns the target, which is of type TestBean. You want the getProxy() method, as the proxy implements the introduced interface. Please let me know if you need further help.

kalfen
Nov 1st, 2004, 08:08 AM
Thanks for the reply,and I am wonder if I can use a ProxyFactoryBean in the applicationContext.xml that reference to the autoproxyed mixin class?this ProxyFactoryBean has some interceptor on the mixin class.
if can,how can I write?