在使用Spring Aop的時候,有時會攔截不到希望攔截的方法...
有時2.0可以但2.5卻不可以~
Spring Aop 代理 有兩種:Java動態(tài)代理和Cglib代理
一般我用的是Cglib代理..<aop:config proxy-target-class="true">
只要在被spring攔截的方法中再調(diào)用其他被代理的對象的方法就可以實現(xiàn)嵌套攔截,
如果調(diào)用自己對象的方法(包括繼承的),
只是普通對象的方法調(diào)用(這時自己是被剝?nèi)チ舜淼臍さ脑紝ο螅?
是不能被攔截的。
Debug下,看一下是不是proxy的類,被proxy的才有可能被攔截..
另外: 使用groovy時,不能對注入groovy Bean的java類進行AOP.(接口編程)
會報以下錯誤:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messenger': BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy74]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy74
<lang:groovy id="messenger" refresh-check-delay="5000" script-source="classpath:groovy/Messenger.groovy">
<lang:property name="message" value="I Can Do The Frug" />
</lang:groovy>
<bean id="testPageAction" class="cn.edu.hust.mes.test.TestPageAction">
<dwr:remote javascript="test"></dwr:remote>
<property name="messenger" ref="messenger"></property>
</bean>