在做spring的前置通知时报错:
java.lang.ClassCastException: class com.sun.proxy.$Proxy5 cannot be cast to class org.wpc.iml.StudentServiceIml
错误原因是:
接收类型写为接口的实现类,如以下代码所示:
StudentServiceIml studentService = (StudentServiceIml)applicationContext.getBean("studentService");
将代码修改为:
IStudentService studentService = (IStudentService)applicationContext.getBean("studentService");
用接口进行接收。
本文分析了在使用 Spring 的前置通知时出现的 ClassCastException 错误,详细解释了错误原因,并提供了将接口实现类改为接口接收类型的解决方案。
1905

被折叠的 条评论
为什么被折叠?



