老师为什么在xml要加<aop:config proxy-target-class="true">这句运行才不报错
我执行一下代码,报错:
ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:applicationContext.xml" );
UserService userService = (UserService) context.getBean( "userServiceImpl", UserServiceImpl.class );
userService.create();
报错如下:
Exception in thread "main" org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userServiceImpl' is expected to be of type 'com.imooc.spring.aop.service.UserServiceImpl' but was actually of type 'com.sun.proxy.$Proxy17'
at org.springframework.beans.factory.support.AbstractBeanFactory.adaptBeanInstance(AbstractBeanFactory.java:417)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:398)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1160)
at com.imooc.spring.aop.application.SpringApplication.main(SpringApplication.java:27)
但是我在xml中<aop:config>标签中添加proxy-target-class="true"这个才不报错,是为什么
25
收起
正在回答 回答被采纳积分+1
2回答
java工程师2020版
- 参与学习 人
- 提交作业 9393 份
- 解答问题 16556 个
综合就业常年第一,编程排行常年霸榜,无需脱产即可学习,北上广深月薪过万 无论你是未就业的学生还是想转行的在职人员,不需要基础,只要你有梦想,想高薪
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星