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版本 ...
随机推荐
- Missing map from Nullable`1 to String. Create using Mapper.CreateMap<Nullable`1, String>. 解决办法
这是一个叫做AutoMapper的插件,主要功能是让两个类的内容进行映射,最常见的例子就是EF查询出的内容映射到一个实体类上去然后返回这个实体类例如: Mapper.CreateMap(); 如果这时 ...
- json字符串转换成对象需要注意的问题
json转换成对象的时候应该尽量避免出现特殊的符号,如“\”这样的字符在转义成数组的时候会被去除掉,最好的例子就是后台返回的内容为存储路径的JSON,这时候最好是把一个斜杠变为两个斜杠,如: [{&q ...
- Android(java)学习笔记101:Java程序入口和Android的APK入口
1. Java程序的入口:static main()方法 public class welcome extends Activity { @Override public void onCreate( ...
- 【BZOJ3925】[ZJOI2015] 地震后的幻想乡(状压期望DP)
点此看题面 大致题意: 有\(n\)个点和\(m\)条边,每条边的权值是一个\(0\sim1\)的随机实数,要你用\(n-1\)条边将图联通,问这\(n-1\)条边中边权最大值的期望最小值. 提示 这 ...
- bazel安装
https://blog.csdn.net/cxq234843654/article/details/70861155 sudo apt-get install openjdk-8-jdk echo ...
- “System.AccessViolationException”类型的未经处理的异常在 System.Data.dll 中发生 其他信息: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏
用管理员身份运行CMD:netsh winsock reset就可以解决
- for in 和 for of的区别详解
for in 和 for of 相对于大家肯定都不陌生,都是用来遍历属性的没错.那么先看下面的一个例子: 例1 const obj = { a: 1, b: 2, c: 3 } for (let i ...
- Java读取各种文件格式内容
所需的jar包哦也不要太记得了,大家可以搜搜,直接上代码: import java.io.BufferedInputStream; import java.io.File; import java.i ...
- jstl(c)标签
一.EL表达式: Expression Language提供了在 JSP 脚本编制元素范围外(例如:脚本标签)使用运行时表达式的功能.脚本编制元素是指页面中能够用于在JSP 文件中嵌入 Java 代码 ...
- 四、Shell 数组
Shell 数组 数组中可以存放多个值.Bash Shell 只支持一维数组(不支持多维数组),初始化时不需要定义数组大小(与 PHP 类似). 与大部分编程语言类似,数组元素的下标由0开始. She ...