[转]Struts2+Spring 中使用AOP拦截execute方法,出现get方法空指针错误 分享
[转]Struts2+Spring 中使用AOP拦截execute方法,出现get方法空指针异常 分享
Struts2+Spring 中使用Spring AOP拦截execute方法,出现get方法NullPointerException 异常,无法获取页面信息,经N多次Google后解决。方法为:<aop:config proxy-target-class="true"> 强制一直使用CGLIB生成代理即可。大致原因是因为我使用了接口,在Action中就用的java的代理从而使get方法失效。具体细节我还不懂,望有高人指点。
解决上述问题还有一方法就是不继承ActionSupport。但还是不知道为什么……估计需要研究一下源码。
Struts2+Spring 中使用Spring AOP拦截execute方法,出现get方法NullPointerException 异常,无法获取页面信息,经N多次Google后解决。方法为:<aop:config proxy-target-class="true"> 强制一直使用CGLIB生成代理即可。大致原因是因为我使用了接口,在Action中就用的java的代理从而使get方法失效。具体细节我还不懂,望有高人指点。
解决上述问题还有一方法就是不继承ActionSupport。但还是不知道为什么……估计需要研究一下源码。
1 楼
tianhandigeng
2012-07-04
我已经这样配置了,但是还是报,我是这样写的:
然后在applicationContext.xml中这样配置:
就报错了,请问一下有什么问题吗?
public class ActionPreResultAdvice implements MethodInterceptor{ public Object invoke(MethodInvocation invocation) throws Throwable { HttpServletRequest request = ServletActionContext.getRequest(); Object returnValue = null; try { returnValue = invocation.proceed(); } catch (Throwable throwable) { request.setAttribute("msg" , "出现异常"); throwable.printStackTrace(); return "exception"; } return returnValue; } }
然后在applicationContext.xml中这样配置:
<!-- 异常处理 --> <bean id="actionPreResultAdvice" class="net.ysccc.exception.ActionPreResultAdvice" /> <aop:config> <aop:advisor pointcut="execution(* com.opensymphony.xwork2..*.*(..))" advice-ref="actionPreResultAdvice"/> </aop:config>
就报错了,请问一下有什么问题吗?