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


准备使用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 基于接口的代理


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM