org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
‘com.ooyhao.springboot.SpringBootDataJpaApplicationTests’: Unsatisfied dependency expressed through field ‘userRepository’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘bean.UserRepository’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
异常信息可以看出:就是userRepository不满足依赖关系,然后就报了一个没有定义这样一个类异常NoSuchBeanDefinitionException,希望至少有一个这样的bean用于装配(expected at least 1 bean which qualifies as autowire candidate. ) (Autowired(required=true) 自动装配为ture,就必须有一个)
重点来了:经过多次的查看我发现自己的项目也没少配置和扫描,就是报这个错,然后经过几个小时的寻找最后发现,其实就是没有把各种包(controller,service,dao,)放在SpringBootApplicationContext.java的同级包或者子包下面。错误示范
正确做法:
切记切记!!!!!!!!!!!!!!!!!!!