【Springboot异常】Unsatisfied dependency expressed through field 'userRepository'

 

错误如下:

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,bean....)放在SpringBootApplicationContext.java的同级包或者子包下面。(可能是自己手抖的原因)。

附上官网一张图:

【Springboot异常】Unsatisfied dependency expressed through field 'userRepository'_第1张图片

 

 

 

你可能感兴趣的:(【Springboot异常】Unsatisfied dependency expressed through field 'userRepository')