|
|
MethodInterceptor for public methods in Controller is not working
Hi,
I have a bean defined in my-servlet.xml for the Controller as quot;myControllerBeanquot; and also, I have added a public method quot;public Object invokeService(params)quot; to this controller. Now, I want to intercept this method and cache the result of this method using EHCache. Code:
lt;bean id=quot;methodCachePointCutquot; class=quot;org..aop.support.RegexpMethodPointcutAdvisorquot;gt; lt;property name=quot;advicequot;gt; lt;ref local=quot;methodCacheInterceptorquot;/gt; lt;/propertygt; lt;property name=quot;patternsquot;gt; lt;listgt; lt;valuegt;.*invoke*lt;/valuegt; lt;/listgt; lt;/propertygt;
lt;/beangt;
lt;bean id=quot;autoProxyquot; class=quot;org..aop.framework.autoproxy.BeanNameAutoProxyCreatorquot;gt; lt;property name=quot;beanNamesquot;gt; lt;listgt; lt;valuegt;myControllerBeanlt;/valuegt; lt;/listgt; lt;/propertygt; lt;property name=quot;interceptorNamesquot;gt; lt;valuegt;methodCachePointCutlt;/valuegt; lt;/propertygt; lt;/beangt;
But the quot;invokeServicequot; method is not getting intercepted. Any idea why?Also, I have another bean quot;myServiceBeanquot; defined in applicationContext.xml file. Can this method interceptor intercept myServiceBean methods also?
thanks for your help,
Forrest
Try quot;.*invoke.*quot; as pattern (note the dot before the last asterisk).
Regards,
Andreas
No, it's still not working. I don't understand why I can't intercept a controller's method. What am I doing wrong here?
can somebody send me a working sample to intercept controller's methods?
Also, I need some sample code for intercepting non-beans. I want MethodInterceptor to be applied to classes that are NOT configured thru Spring.
thx.
here is the complete configuration I have.Code:
lt;bean id=quot;myControllerquot; class=quot;com.mycompany.controller.MyControllerquot;gt;
lt;/beangt;
lt;bean id=quot;methodCachePointCutquot; class=quot;org..aop.support.RegexpMethodPointcutAdvisorquot;gt; lt;property name=quot;advicequot;gt; lt;ref local=quot;methodCacheInterceptorquot;/gt; lt;/propertygt; lt;property name=quot;patternsquot;gt; lt;listgt; lt;valuegt;handleRequestlt;/valuegt; lt;valuegt;.*invoke*.*lt;/valuegt; lt;/listgt; lt;/propertygt;
lt;/beangt;
lt;bean id=quot;autoProxyquot; class=quot;org..aop.framework.autoproxy.BeanNameAutoProxyCreatorquot;gt; lt;property name=quot;beanNamesquot;gt; lt;listgt; lt;valuegt;myControllerlt;/valuegt; lt;/listgt; lt;/propertygt; lt;property name=quot;interceptorNamesquot;gt; lt;valuegt;methodCachePointCutlt;/valuegt; lt;/propertygt;
lt;/beangt; |
|