com.sun.proxy.$Proxy25 cannot be cast to com.levi.service.impl.ProductServiceImpl和proxy-target-class
来源:互联网 发布:淘宝客服每天工作内容 编辑:程序博客网 时间:2024/05/19 00:43
刚刚写一个项目的时候出现了一个错误 com.sun.proxy.$Proxy25 cannot be cast to com.levi.service.impl.ProductServiceImpl,之前报错的代码为:
ProductServiceImpl p=(ProductServiceImpl) applicationContext.getBean("productService");上面的ProductServiceImpl类是一个实现的ProductService接口的。利用spring ioc获取这个productService bean的时候,不能转换为ProductServiceImpl,而只能转为它的父接口ProductService。查了很多资料,发现是Spring AOP的一个配置文件问题。proxy-target-class这个参数。将spring配置文件改为下面就行了:
<!-- 配置事务切面 --> <aop:config proxy-target-class="true"> <aop:pointcut id="serviceOperation" expression="execution(* com.levi.service..*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation" /> </aop:config> <!-- 自动扫描加载构建bean --> <context:component-scan base-package="com.levi" />proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。
0 0
- com.sun.proxy.$Proxy25 cannot be cast to com.levi.service.impl.ProductServiceImpl和proxy-target-class
- com.sun.proxy.$Proxy25 cannot be cast to SessionImplementor
- ssh报错java.lang.ClassCastException: com.sun.proxy.$Proxy6 cannot be cast to org.service.impl.EmpServi
- java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.Question
- java.lang.ClassCastException: com.sun.proxy.$Proxy27 cannot be cast to com.bbk.n002.service.Question
- 9.ClassCastException: com.sun.proxy.$Proxy24 cannot be cast to com.rchange.service.SysUser
- Java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to com.bjsxt.service.UserServiceI
- java.lang.ClassCastException: com.sun.proxy.$Proxy8 cannot be cast to com.bjsxt.service.UserServiceI
- com.sun.proxy.$Proxy29 cannot be cast to
- Spring:com.sun.proxy.$proxy0 cannot be cast to XXX
- com.sun.proxy.$Proxy0 cannot be cast to ** 解决方法
- com.sun.proxy.$Proxy4 cannot be cast to spring.HelloService
- Spring com.sun.proxy.$Proxy6 cannot be cast to
- Spring:com.sun.proxy.$Proxy6 cannot be cast to
- hibernate-spring测试报错:com.sun.proxy.$Proxy44 cannot be cast to com.mm.service.imp.RoleServic
- java.lang.ClassCastException: com.sun.proxy.$Proxy* cannot be cast to***问题解决方案
- com.sun.proxy.$Proxy2 cannot be cast to com.vnb.HelloWorldImpl1
- ClassCastException: com.sun.proxy.$Proxy2 cannot be cast...
- c#事件复习
- Swing超基础学习总结——5、菜单(JMenu、JMenuBar、JMenuItem)
- css属性之边框属性
- 【剑指offer】面试题6:重建二叉树
- C++ hdoj 2040
- com.sun.proxy.$Proxy25 cannot be cast to com.levi.service.impl.ProductServiceImpl和proxy-target-class
- Sklearn 用户手册 一:机器学习初体验
- IPC之Posix信号量详解
- 白盒测试方法和工具
- android网络HTTP和TCP
- c#协变-逆变复习
- R的神经网络包
- 散列表、散列函数
- CCNA笔记2--OSI参考模型与设备的关系