在使用Spring AOP时,遇到如下的错误:

Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.spring.test.setter.Instrumentalist
at com.spring.test.setter.test.main(test.java:12)

  看报错信息,显示的是动态代理生成的类无法转换到我们自定义的实现类。

  解决办法:

  在aop:config标签中添加 proxy-target-class="true" 即可。

  【解释说明】

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

  由于生成代理类有两种方式:JDK和CGLIB,一种是基于接口的,一种是基于类的。

  如果添加上面的属性则使用基于类的cglib的方式,相反,如果没有写或者是false则通过jdk的基于接口的方式生成代理类。

  

  当然,如果本身不是基于接口的,那么会自动使用cglib的方式,在这里很奇怪为什么没有自动走cglib的方式。

  个中缘由,还得去看aop的源码,这里先做下记录。

  下面是我自己的spring配置文件,仅供参考

    <aop:config proxy-target-class="true">
<aop:aspect ref="audience">
<aop:before pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="takeSeats"/>
<aop:before pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="turnOffCellPhones"/>
<aop:after-returning pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="applaud"/>
<aop:after-throwing pointcut="execution(* com.spring.test.action1.Performer.perform(..))"
method="demandRefund"/>
</aop:aspect>
</aop:config>

Spring aop报错:com.sun.proxy.$Proxyxxx cannot be cast to yyy的更多相关文章

  1. Spring AOP报错

    八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRe ...

  2. Spring AOP 报错org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'XXXXXX' defined in class path resource..........

    完整报错如下: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'befo ...

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

    准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因 解决方案:在 aop-config配置添加上: proxy ...

  4. Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误

    [转] 解决方法: http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-Applicati ...

  5. 解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element

    解决eclipse spring配置报错:cvc-elt.1: Cannot find the declaration of element 'beans'.Referenced file conta ...

  6. Spring.之.报错:Caused by: java.lang.IllegalArgumentException: No Spring Session store is configured: set the 'spring.session.store-type' property

    Spring.之.报错 No Spring Session store is configured springboot在启动的时候报如下错误: Error starting ApplicationC ...

  7. Spring Boot报错 MultipartException The temporary upload...

    Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...

  8. Spring Boot 报错记录

    Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...

  9. 报错com.github.pagehelper.PageHelper cannot be cast to com.github.pagehelper.Dialect

    报错com.github.pagehelper.PageHelper cannot be cast to com.github.pagehelper.Dialect spring以及mybatis版本 ...

随机推荐

  1. vuejs数据和事件

    <body> <div id='root'>{{number}}</div> <script> new Vue({ el:'#root', data:{ ...

  2. 感知器及其Python实现

    感知器是由美国计算机科学家罗森布拉特(F.Roseblatt)于1957年提出的.感知器可谓是最早的人工神经网络.单层感知器是一个具有一层神经元.采用阈值激活函数的前向网络.通过对网络权值的训练,可以 ...

  3. pyqt4 python2.7 中文乱码的解决方法

    import sysimport localefrom PyQt4.QtGui import *from PyQt4.QtCore import *from untitled import Ui_Di ...

  4. 最近面试前端岗位,汇总了一下前端面试题(JS+CSS)

    JavaScript 运行机制 1. 单线程(用途决定,需要与用户互动以及操作DOM) 2. 分同步任务(主线程)与异步任务(任务队列),只有任务队列通知主线程某个任务可以执行了,该 任务才会进入主线 ...

  5. Oracle问题分析采集数据的方法

    1.背景: 运维人员或多或少都会遇到分析问题.分析故障的时候,往往在碰到一些棘手的问题事,我们都会往更深层次的专家进行求助.不管是二线专家还是Oracle全球服务工程师(后文称GCS工程师),往往都会 ...

  6. selenium 双击元素

    #定位元素 pod_input = driver.find_element(By.ID, 'j_idt9:searchForm:j_idt11:toSelectorLocation:toSelecto ...

  7. 汇编 if else 例子

    .text .global  _start _start: mov r1,#1 mov r2,#2 cmp r1, r2 bgt  branch1 add  r3,r1,r2 b  end branc ...

  8. https://www.atlassian.com

    https://www.atlassian.com 解决:confluence 5.9.4 一次性恢复30个插件 - 简书 https://www.jianshu.com/p/c32d8aa739b8 ...

  9. 懒人的mysql管理脚本

    最近常用到的命令,太懒不想打太多 1,mysql启动,重启,停止脚本 echo '/usr/local/mysql5/support-files/mysql.server $1'>>/us ...

  10. JZOJ 5809. 【NOIP2008模拟】数羊

    5809. [NOIP2008模拟]数羊 (File IO): input:sheep.in output:sheep.out Time Limits: 1000 ms  Memory Limits: ...