Spring Aop 拦截 Struts2 Action 问题
<aop:aspectj-autoproxy proxy-target-/> <aop:config> <aop:aspect ref="profiler"> <aop:pointcut id="test" expression="(execution(* cn.com.xyz.action.*Action.*()))" /> <aop:around pointcut-ref="test" method="profile" /> </aop:aspect> </aop:config>??
通过一下这篇文章:http://xuxingyin.iteye.com/blog/600091
?
??? <result name="loginSuc">${nextPage}</result>??? <result name="loginFail">login.jsp</result>
?? </action>
spring的applicationcontext.xml配置文件:
//action
<bean id="memberAction"
?? scope="prototype">
?? <property name="memberService">
??? <ref bean="memberService" />
?? </property>
</bean>
<!-- 自动代理对象 -->
<bean id="autoProxy"
?? value="true"/> //注意这里!
?? <property name="beanNames">
??? <list>
???? <value>*Action</value>
??? </list>
?? </property>
?? <property name="interceptorNames">
??? <list>
???? <value>checkArgumentsAdvice</value>
???? <value>exceptionLogger</value>
??? </list>
?? </property>
</bean>
当struts2的action没有配置动态方法调用的时候,运行正常。当使用动态方法调用的时候,运行时报
类似: NoSuchMethodException:$Proxy6.login() 的错误,解决办法是使用CGLib实现aop,加上
<property name="proxyTargetClass" value="true"/>
如果使用 aop:方式的话,加上<aop:aspectj-autoproxy proxy-target-路径一定要配置正确要不出莫名其妙的问题,这里总结下留下作为以后参考!