异常如下:报NoSuchMethodException异常,或者只能拦截service和dao 的实现类,
NoSuchMethodException:$Proxy6.login()
原因:
spring3 默认使用JDK动态代理来实现AOP,如果struts2使用的动态方法调用,则spring3只能代理实现了接口的类,而不能代理action控制器,
解决方法:
给spring3 AOP修改配置参数:
<aop:aspectj-autoproxy proxy-target-class="true"/>
<bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator">
<property name="proxyTargetClass" value="true"/>
</bean>
这样spring3会采用CGLIB库来给没有接口的类生成代理,进而实现AOP,
本文解决Spring3在与Struts2整合时遇到的NoSuchMethodException异常,通过调整配置参数使用CGLIB库来代理未实现接口的类,实现面向切面编程(AOP)。
724

被折叠的 条评论
为什么被折叠?



