Spring中bean注入报错的几种原因

报错类型:Error creating bean with name ‘userController’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com...service.UserService com.taotao.sso.controller.UserController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.taotao.sso.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

可能原因:
1.spring-mvc配置文件错误,是否对所建的包进行了扫描
Spring中bean注入报错的几种原因
2.mapper.xml文件的命名空间namespace是否跟mapper文件的路径一致;
3.若确定没有以上错误,可以查看编译是否出错,在classes文件中查看自己的配置文件是否编译成功。若为编译出错在项目的pom.xml文件中加入以下代码即可
Spring中bean注入报错的几种原因