在使用Spring AOP时,遇到转换错误:
来源:互联网 发布:触碰心灵的话 知乎 编辑:程序博客网 时间:2024/05/05 19:26
转载自http://www.cnblogs.com/xing901022/p/4264172.html
在使用Spring AOP时,遇到如下的错误:
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to com.spring.test.setter.Instrumentalistat 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>
0 0
- 在使用Spring AOP时,遇到转换错误:
- Spring AOP 一个类实现接口时遇到id类型转换错误
- 【spring】IllegalArgumentException Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误
- Spring AOP报错处理 Can not set field to $Proxy 在spring中使用事物或AOP遇到的错误
- 使用 spring aop 在DispatchAction中遇到的问题
- 使用 spring aop 在DispatchAction中遇到的问题
- Spring AOP使用ASPECTJ错误
- spring aop(三)--aop在spring的使用
- 在配置spring的数据源时遇到的奇葩错误
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- Spring AOP代理时 ClassCastException: $Proxy0 cannot be cast to (类型转换错误)
- 正确配置spring aop,在controller中使用AOP
- 在spring使用annotation时错误
- 在使用CommonComplexAdapter时遇到的类型无法转换问题
- spring使用AOP时the prefix aop for element is not bound.和no declaration can be found错误
- 在使用Struts时遇到的各种错误总结
- 使用spring aop 进行用户行为跟踪错误
- 分类模型的性能评估——以SAS Logistic回归为例
- php判断一个参数在一个数组中是否存在
- ubantu16.04和win8.1双系统的时间差问题
- 为什么谷歌要执行严格的代码编写规范
- 安装OpenVPN报错:lzo enabled but missing
- 在使用Spring AOP时,遇到转换错误:
- laypage 分页控件使用方法
- AUC与ROC - 衡量分类器的好坏
- 深入了解MyBatis参数
- 独立开发者能够从这位作家身上学些什么
- 二分类模型性能评价(R语言,logistic回归,ROC曲线,lift曲线,lorenz曲线)
- Swift学习第十三枪-使用Swift开发IOS中蓝牙4.0的开发流程
- Eclipse Java Servlet中使用另一个项目中类或方法
- 体会大师们的智慧-优化冒泡排序