Spring Aop 注意...

在使用Spring Aop的时候,有时会拦截不到希望拦截的方法...

有时2.0可以但2.5却不可以~

Spring Aop 代理 有两种:Java动态代理和Cglib代理

一般我用的是Cglib代理..<aop:config proxy-target-class="true">

 

只要在被spring拦截的方法中再调用其他被代理的对象的方法就可以实现嵌套拦截,

如果调用自己对象的方法(包括继承的),

只是普通对象的方法调用(这时自己是被剥去了代理的壳的原始对象),

是不能被拦截的。

 

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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值