java SpringBootApplication scanBasePackages未读取子包
我在nexus上发布了一个具有包id的公共库
x.xx.common
它包含常见的外部客户端代理接口的子包
使用此库的项目具有包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中构造函数的参数0。常见的服务impl。AuditServiceImpl需要类型为“x.xx”的bean。常见的找不到的LogProxy“”
每个接口代理都会出现该错误
# 1 楼答案
向要扫描的子包类添加注释。分别向类添加
@Component
、@Service
或@Repository
等注释。 对于注释:@SpringBootApplication(scanBasePackages = {"x.xx"})
假设子包
x.xx
中有一个名为Abc
的类,那么将注释@Component添加到该类中@Component class Abc{}
这将有助于阅读子包类
要了解上述注释之间的差异,请执行以下操作:What's the difference between @Component, @Repository & @Service annotations in Spring?
# 2 楼答案
我已经弄明白了,显然AppClass
@EnableFeignClients
也需要添加基类因此,对于任何有相同问题的人,我的
AppClass
现在有以下注释