Spring aop报错:com.sun.proxy.$Proxyxxx cannot be cast to yyy
在使用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的更多相关文章
- Spring AOP报错
八月 01, 2016 10:08:48 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRe ...
- 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 ...
- Spring aop报错:com.sun.proxy.$Proxy cannot be cast to xxx
准备使用AOP记录所有NamedParameterJdbcTemplate操作数据时的所有日志,没想到出现这个错误,折腾了好久,终于找出原因 解决方案:在 aop-config配置添加上: proxy ...
- Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误
[转] 解决方法: http://forum.springsource.org/showthread.php?85016-IllegalArgumentException-with-Applicati ...
- 解决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 ...
- 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 ...
- Spring Boot报错 MultipartException The temporary upload...
Spring Boot报错:尤其是在处理Ribbon这类接口调用型的负载均衡组件,常见问题 ERROR o.a.c.c.C.[.[.[.[dispatcherServlet] - Servlet.se ...
- Spring Boot 报错记录
Spring Boot 报错记录 由于新建的项目没有配置数据库连接启动报错,可以通过取消自动数据源自动配置来解决 解决方案1: @SpringBootApplication(exclude = Dat ...
- 报错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版本 ...
随机推荐
- 2018.6.18 MyEclipse导入jquery-1.8.0.min.js等文件报错的解决方案
MyEclipse导入jQuery-1.8.0.min.js等文件的时候有时候会报了一堆missing semicolon的错误.怎么解决这个报错呢?方法如下: 1.选中报错的jquery文件例如&q ...
- 使用pip 提示UnicodeDecodeError: 'ascii' codec can't decode解决方法
python目录 Python27\Lib\site-packages 建一个文件sitecustomize.py 内容写: import sys sys.setdefaultencoding('gb ...
- c++question 004 c++基本数据类型有哪些?
(1)signed int类型 整数型 占内存4个字节 一个字节byte 占8个二进制位 一个整型就占32位 (2)short int 短整型 占内存2个字节 一个短整型占16位 (3)long i ...
- wepy一些问题和解决方案
wepy一些问题和解决方案 小程序开发和传统的web开发有相识的地方,但是也有不同的地方,要区分. computed属性名和props属性名重复 如果那个组件的渲染值是重名的computed属性,每次 ...
- abs的个人博客 http://abs001.top/blog
abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 abs的个人博客 a ...
- Apache 查找httpd.conf文件
Linux下查找httpd.conf文件 $ find / -name httpd.conf
- 【前端_js】理解 JavaScript 的 async/await
async 和 await 在干什么 任意一个名称都是有意义的,先从字面意思来理解.async 是“异步”的简写,而 await 可以认为是 async wait 的简写.所以应该很好理解 async ...
- Mysql主从数据同步cheksum问题
做主从同步时出现问题,show slave status显示错误: Last_IO_Error: Got fatal error from master when reading data from ...
- 数据结构-队列(Queue)
#include <stdio.h> #include <stdlib.h> #define LIST_INIT_SIZE 10 #define LISTINCREMENT 1 ...
- 开源数据库中间件-MyCat
开源数据库中间件-MyCat产生的背景 如今随着互联网的发展,数据的量级也是成指数的增长,从GB到TB到PB.对数据的各种操作也是愈加的困难,传统的关系型数据库已经无法满足快速查询与插入数据的需求.这 ...