sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.92k stars 1.26k forks source link

我想问一下 各个模块加载自己的上下文的时候,为什么会出现重复加载某个类的情况 #1329

Open xycf2233 opened 2 weeks ago

xycf2233 commented 2 weeks ago

如题。在各个模块加载自己上下文时控制台会大量打印“Component was already registered:xxxx”。 重复的扫描让项目启动时间变得很长。二三十分钟启动真的很难以接受。

CrazyHZM commented 2 weeks ago

检查一下是不是配置的ComponentScan里的扫描路径有重叠

xycf2233 commented 2 weeks ago

没有重叠,出现问题的是当前项目下的common-dal中的mapper类。通过MapperScan指定了扫描路径,但是在SpringContextInstallStage类的doRefreshSpringContext方法中,多线程去刷新各个模块上下文(ctx.refresh())的时候,应该是每个线程都重复去扫描了

HzjNeverStop commented 1 week ago

@xycf2233 你好,可以给出一个示例代码来复现这个问题吗