【Bug】Spring Boot 多模块开发 找不到依赖服务

本文分析了Spring Boot多模块项目中因启动类位置导致的依赖服务找不到问题,指出项目启动时仅扫描启动类所在包及其子包的类。通过展示项目结构和Spring Boot官方建议,提出了解决方案:一是手动指定扫描包路径,二是调整启动类至合适位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

报错信息如下

 Unsatisfied dependency expressed through field 'userManagerService'; 
 nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: 
 No qualifying bean of type 'dubbo.exercise.one.basic.user.service.UserManagerService' available: 
 expected at least 1 bean which qualifies as autowire candidate. 
 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Spring boot 的官网中有这样一段内容

We generally recommend that you locate your main application class in a root package above other classes. The @SpringBootApplication annotation is often placed on your main class, and it implicitly defines a base “search package” for certain items.

Spring Boot 项目在启动的时候是从启动类所在的包路径开始扫描相关类

接下来看看我们的项目结构

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值