在Spring的容器中获取bean的时候遇到了这个错误,大致意思是无法将代理转换为我们想要的类
我的代码是:
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
UserDAOMySQLImpl udao= (UserDAOMySQLImpl) context.getBean("userDAO");
解决办法:这里需要这applicationContext.xml里的aop:config 标签加上这样一个配置
<aop:config proxy-target-class="true">
这样的方式便是使用了cglib的方式来创建类,否则这是使用jdk的代理创建!但是我不知道为什么jdk的代理创建就是不行的