Spring获取bean报错Bean named ‘xxx‘ is expected to be of type ‘xxx‘ but was actually of type ‘com.sun.pro
Posted mp-ui
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring获取bean报错Bean named ‘xxx‘ is expected to be of type ‘xxx‘ but was actually of type ‘com.sun.pro相关的知识,希望对你有一定的参考价值。
这是我用Spring整合Mybatis并配置事务时,获取bean时得到的一个错误
Bean named 'xxx' is expected to be of type 'xxx' but was actually of type 'com.sun.proxy.$Proxy19'
这个就是我的Service层
这个是我获取bean的代码,如果第二个参数是CourseService.class
的话就没有什么问题,但是因为我在CourseServiceImpl中加了几个方法所以需要用到它的实现类,所以必须获取CourseServiceImpl
CourseServiceImpl courseService = applicationContext.getBean("courseService",CourseServiceImpl.class);
解决方法:
applicationContext.xml里面修改代理模式为proxy-target-class="true"
<tx:annotation-driven transaction-manager="dataSourceTransactionManager" proxy-target-class="true" />
以上是关于Spring获取bean报错Bean named ‘xxx‘ is expected to be of type ‘xxx‘ but was actually of type ‘com.sun.pro的主要内容,如果未能解决你的问题,请参考以下文章
Spring Boot报错:Error creating bean with name 'sqlSessionFactory' ...
Spring 报错:Error creating bean with name
spring-boot导入redis依赖后报错 Error creating bean with name ‘redisConnectionFactory‘
spring 的 ApplicationContext.getBean(type) 无法获取bean,报错
Spring 定时器 使用quartz 报错问题 Error creating bean with name 'reportTask' defined in file 求解