java.lang.ClassCastException: sun.proxy.$Proxy11 cannot be cast to分析:
报这个错,只有一个原因,就是你转化的类型不对.
[color=orange] 分析1:[/color]
如果你的类是一个单实体类,也就是没有继承或是接口别的类.
public class HjmServiceImpl {}
那么这样写就可以:
HjmServiceImpl service = (HjmServiceImpl)ctx.getBean("HjmServiceImpl");
但当你的这个类配置在AOP切面上时,就会报上面错,详情见AOP动态代理;则必须以接口方式获取,见2
[color=orange] 分析2:[/color]
如果你的类,一般像SERVER的实体类,是接口过的.
public class HjmServiceImpl implements HjmExampleService{}
那么就一定要写成如下:
HjmExampleService service = (HjmExampleService)ctx.getBean("HjmServiceImpl");
看出区别没有.接口过父类的子类,在强制转换的时候,一定要用接口父类来定义.
[color=red]attr: Spring 的事务机制注意要点:[/color]
当你调用的方法是父类中的方法时,需要给父类的方法配置事务
若想使用Spring的事务管理,刚业务类需要从Spring容器中获取
报这个错,只有一个原因,就是你转化的类型不对.
[color=orange] 分析1:[/color]
如果你的类是一个单实体类,也就是没有继承或是接口别的类.
public class HjmServiceImpl {}
那么这样写就可以:
HjmServiceImpl service = (HjmServiceImpl)ctx.getBean("HjmServiceImpl");
但当你的这个类配置在AOP切面上时,就会报上面错,详情见AOP动态代理;则必须以接口方式获取,见2
[color=orange] 分析2:[/color]
如果你的类,一般像SERVER的实体类,是接口过的.
public class HjmServiceImpl implements HjmExampleService{}
那么就一定要写成如下:
HjmExampleService service = (HjmExampleService)ctx.getBean("HjmServiceImpl");
看出区别没有.接口过父类的子类,在强制转换的时候,一定要用接口父类来定义.
[color=red]attr: Spring 的事务机制注意要点:[/color]
当你调用的方法是父类中的方法时,需要给父类的方法配置事务
若想使用Spring的事务管理,刚业务类需要从Spring容器中获取