Reputation: 31
I'm trying to intercept the Struts2's action class's method using Spring AOP but it didn't work. The bean returned from the Spring web Application context, doesn't simply has the Action classes's method (checked using Reflection). But it has only the methods of ActionSupport class(Struts API) which our Action classes extends from.
I could see in the log :
16:55:20,328 DEBUG [org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator] (http-01h3463916-172.20.211.235-8543-5) Creating implicit proxy for bean 'deviceAction' with 0 common interceptors and 2 specific interceptors
16:55:20,328 DEBUG [org.springframework.aop.framework.JdkDynamicAopProxy] (http-01h3463916-172.20.211.235-8543-5) Creating JDK dynamic proxy: target source is SingletonTargetSource for target object [com.tcs.oss.tims.deviceManagement.action.DeviceAction@70103f6e]
16:55:20,332 DEBUG [org.springframework.beans.factory.support.DefaultListableBeanFactory] (http-01h3463916-172.20.211.235-8543-5) Finished creating instance of bean 'deviceAction'
And the action bean object returned is of type: class com.sun.proxy.$Proxy36
Interestingly, other beans(not the action bean) even though they are adviced by spring AOP, the returned proxy object includes all the methods of the bean declared classes.
Any help is appreciated...
Upvotes: 1
Views: 381
Reputation: 31
Finally I made it to work. It was due to the Spring's proxy mechanism. --- Interface based proxy(JDK proxy) or Class based proxy(CGLib based proxy). Since, my action class was extending from ActionSupport class which in turn has a interface implementations .. A JDK proxy was created for the Action class -- which doesn't have any method specific(non-inheritance) to the Action class.
Adding proxy-target-class="true" attribute, in the AOP configuration, made the Spring to generate CGLib(need to add CGLib in the Classpath) based proxy.. which now has the non-inheritance methods of Action class.
Thanks anyway ...;)
Upvotes: 0