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的同级包或者子包下面。错误示范
在这里插入图片描述
正确做法:
在这里插入图片描述

切记切记!!!!!!!!!!!!!!!!!!!

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐