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.94k stars 1.26k forks source link

模块化配置后报Bean重复错误 #1188

Closed shuiyouzhi closed 1 year ago

shuiyouzhi commented 1 year ago

SOFA版本:3.18.0

3个模块中 start是启动入口,包含了2个模块分别为TestA和TestB,其中TestA和TestB中都存在TestService 3个模块中 sofa-module.properties中的Module-Name各不相同 项目启动后报Bean 重复错误,但是官网定义如图1, Demo项目如图2, 报错如图3。麻烦帮忙看下我是否对模块化的理解有误。 Bean注册方式:@Components @ComponentScan 全sofa模块扫描

图1: image

图2: image

图3: image

HzjNeverStop commented 1 year ago

SOFA 模块会自动加载当前 maven 模块中 resources/spring/ 目录下的xml资源作为 Spring 资源,因此需要通过 xml 去扫描各个模块中的 Bean。 同时需要调整启动类的默认注解扫描范围,不要加载到模块中的 bean

shuiyouzhi commented 1 year ago

感谢回复,Bean注册方式只能是xml方式,目前不支持原生态注解方式注册Bean。