問題描述:
<aop:config proxy-target-class="false"><aop:pointcutexpression="execution(* test.service.impl.User*.sendxinxi(..))"id="checklogin" /><aop:advisor advice-ref="txAdvice" pointcut-ref="checklogin" /><aop:aspect id="aspect" ref="aspectBean"><aop:before method="print" pointcut-ref="checklogin" /></aop:aspect></aop:config>
上述代碼配置切入在業務層的所有方法,代碼運行正常。
如果切入Acton,例如
<aop:pointcut expression="execution(* test.action.LoginAction.execute())" id="checklogin"/>
會出現jsp提交的username和password的值無法注入到Action中。
經過一番搜尋得知原因:
在struts2的表單資料對應到action的對象過程之前,是先執行struts2內部的預設攔截鏈,當然也可以顯式定義,例如
<interceptor-ref name ="defaultStack"/>
注意strut2的攔截器:
public String intercept(ActionInvocation actionInvocation) throws Exception
當用自訂AOP方法攔截struts2的action時,雖然自訂的切入方法能正常運行,但截斷了struts2預設攔截器ActionInvocation的傳遞,也就中斷了表單資料向action內對象映射傳遞。
暫時未找到解決方案。
參考連結:
http://topic.csdn.net/u/20090206/12/ec2c23b6-b6d9-43e8-b176-3dc770f817fb.html