java - SpringBootApplication scanBasePackages 不读取子包
问题描述
我在 nexus 上发布了一个具有包 ID 的通用库
x.xx.common
包含常用的feign客户端代理接口的子包
使用此库的项目具有包 ID。
x.xx.account
x.xx.device
这些项目中的每一个在根目录中都有其应用程序类
x.xx.account.AppClass
x.xx.device.AppClass
这些课程中的每一个都有
@SpringBootApplication(scanBasePackages = {"x.xx"})
出于某种原因,两个项目都看不到子包下的任何代理接口
x.xx.common.proxy
x.xx.common.configuration
我尝试将代理接口直接移动到主包下
x.xx.common
但它也失败了
x.xx.common.service.impl.AuditServiceImpl 中构造函数的参数 0 需要找不到类型为“x.xx.common.LogProxy”的 bean。
每个接口代理都会出现该错误
解决方案
向要扫描的子包类添加注释。@Component
分别将,@Service
或等注释@Repository
分别添加到类中。对于注释:
@SpringBootApplication(scanBasePackages = {"x.xx"})
假设Abc
子包中有一个类命名x.xx
,所以在该类中添加注解@Component。
@Component
class Abc{}
这将有助于阅读子包类。
要详细了解上述注解之间的区别: Spring 中的@Component、@Repository 和@Service 注解有什么区别?
推荐阅读
- android - 在 PC 中安装 android 手机作为串口设备
- mysql - 选择彼此不同超过一秒的行MYSQL
- android - 何时构建/创建/编译字符串?
- javascript - Firebase 检测数据是否存在
- android - Xamarin Android NotificationCompat 不显示且没有错误
- bash - Jenkins:执行 Bash/Shell 脚本时转义引号
- android - 如何扫描 wifi 或检查 wifi 是否为 2.4 ghz 频段?
- javascript - nuxt 2 的节点内存泄漏
- javascript - Angular 中的 RouterLink 使用 Javascript
- apache - 现有文件系统目录的 Apache 重写规则