报错:Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

这两天自己搭spingmvc,总是报错,找不到自动注册的bean

Could not autowire field: private lf.service.UserService lf.controllers.UserController.userService; 
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No qualifying bean of type [lf.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)}

建一个单元测试,看看能不能跑起来,如果能跑起来,说明是web配置错误,如果不能说明类写的有问题。
类检查方面:
1.是否在加了@Controller  @Repository @Service 注解
@Controller
@RequestMapping(value = "/user")
public class UserController {
@Service
public class UserServiceImpl implements UserService{
@Repository
public interface UserDao {

2.spring-mvc的配置中 是否自动注册了controller类
  
  
3.spring的配置中,是否注册了用到的类
  
       
              
       
4.如果用了mybatis,看看配置的路径是否正确
    
        
        
 
        
        
    
 
mapper的namespace是否正确

    
        
如果还跑不起来,就可能是web.xml里面丢了listener
    
        org.springframework.web.context.ContextLoaderListener
    

我的目录如下
报错:Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}_第1张图片



你可能感兴趣的:(spring,spring,自动注册报错)