今天在学习SpringAop时出现了如下问题:
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy2 cannot be cast to org.Test.DaoImpl.addStudentImpl
翻译过来大致意思是无法转换到我们自定义的实现类。
addStudentImpl test= (addStudentImpl) context.getBean("addStudent");
解决办法:在aop:config标签中添加 proxy-target-class="true" 即可。
<aop:config proxy-target-class="true">