您的位置:首页 > 编程语言 > Java开发

【异常篇-spring】org.springframework.beans.factory.BeanNotOfRequiredTypeException

2018-03-01 13:59 627 查看
报错异常:

2018-03-01 13:44:18.091 [localhost-startStop-1] ERROR o.a.c.c.C.[.[.[/zsedu-score-query-webserver-webapp] -- StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scoreQueryController': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'studentService' must be of type [com.nenglong.rrt.webserver.service.exam.StudentService], but was actually of type [com.nenglong.rrt.webserver.service.user.impl.StudentServiceImpl$$EnhancerBySpringCGLIB$$9f0ce91f]
at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(Common...............................
at java.lang.Thread.run(Unknown Source)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'studentService' must be of type [com.xxx.webserver.service.exam.StudentService], but was actually of type [com.xxx.webserver.service.user.impl.StudentServiceImpl$$EnhancerBySpringCGLIB$$9f0ce91f]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:364)
..............................
解决方法:@Resource
private StudentService<Student, StudentForm> studentService;改为@Resource(name="studentService2")
private StudentService<Student, StudentForm> studentService;原理:默认按照名称进行装配,名称可以通过name属性进行指定,如果没有指定name属性,当注解写在字段上时,默认取字段名进行按照名称查找。com.xxx.webserver.service.user包下也有一个studentService接口,取bean时未指定名称导致到的..service.user包下的接口类型不匹配。
备注:...user包下的studentService实现类代码@Service("studentService")
public class StudentServiceImpl implements studentService
{
.......
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐