TransactionProxyFactoryBean 代理事务 $Proxy5 cannot be cast to异常解决方法

异常如下:

     [com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor]-[ERROR] $Proxy5 cannot be cast to               com.student.service.StudentService

java.lang.ClassCastException: $Proxy5 cannot be cast to com.student.service.StudentService


解决方法:

 导致出问题的代码片段:

StudentService studentService= (StudentService) BeanFactory.getBean("studentService");

              应该改为Service Service= (Service) BeanFactory.getBean("studentService");

                     其中StudentService 实现了Service接口

这主要代理需要用到接口


             Ps: 所以通过这种代理的话,必须声明一个接口(例如Service),并在接口中声明实现类(例如:StudentService)所需要的方法,这样 Service Service= (Service) BeanFactory.getBean("studentService");  中,service来调用StudentService 实现的方法。


posted @ 2015-03-19 23:24  一叶扁舟YE  阅读(205)  评论(0)    收藏  举报