首页 > 编程语言 > 详细

Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx

时间:2016-01-17 14:45:35      阅读:6545      评论:0      收藏:0      [点我收藏+]

准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因

技术分享

解决方案:在 aop-config配置添加上:

proxy-target-class="true"

 

贴上我的配置AOP配置:

 <aop:config proxy-target-class="true">
        <aop:pointcut id="pointcut" expression="execution(public * org.xx.util.JdbcUtil.*(..))"/>
        <aop:aspect id="logAspect" ref="logInterceptor">
        <aop:before method="before" pointcut-ref="pointcut"/>
        <aop:after-returning method="afterRunning" pointcut-ref="pointcut"/>
        </aop:aspect>
    </aop:config>

 

 按照博客的说法:http://blog.csdn.net/oathevil/article/details/7244694

注意:proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理

Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx

原文:http://www.cnblogs.com/rongguang/p/5137173.html

(0)
(1)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!