java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析

报这个错,只有一个原因,就是你转化的类型不对.


如果你的类是一个单实体类,也就是没有继承或是接口别的类.


public class HjmServiceImpl {}


那么这样写就可以:


HjmServiceImpl service = (HjmServiceImpl)ctx.getBean("HjmServiceImpl");


但如果你的类,一般像SERVER的实体类,是接口过的.


public class HjmServiceImpl implementsHjmExampleService{}


那么就一定要写成如下:


HjmExampleService service = (HjmExampleService)ctx.getBean("HjmServiceImpl");


看出区别没有.接口过父类的子类,在强制转换的时候,一定要用接口父类来定义.

原文地址:https://www.cnblogs.com/xiaowangba/p/6314222.html