spring 在自动注入bean的时候无法自动注册UserService这个类

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.baobaotao.service.UserService com.baobaotao.web.LoginController.userService; nested exceptio
n is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.baobaotao.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)}

com.baobaotao.service.UserService Autowired
不成功请问是什么问题

如果是用xml配置的,确定下bean的name(id)是否正确,配置是否完整,如果是用注解,确定下你xml配置里面的扫描包是否扫描到了UserService这个java类所在的包,并且看下UserService类的注解配置是否正确!
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-09-08
NoSuchBeanDefinitionException: No matching bean of type [com.baobaotao.service.UserService] found for dependency,
没找到com.baobaotao.service.UserService; 看下是不是名字写错了追问

没有写错

本回答被网友采纳