Spring 独特的 bean - 多个模块

Spring unique bean - multiple modules

我正在开发依赖于模块 1 和模块 2 的模块 3。

模块 1 具有以下 类:

class Module1Service {
    @Autowired
    MyBean myBean;
    .....
}

@Component("module1MyBean")
class MyBeanImpl implements MyBean{

}

模块 2 具有以下 类:

class Module2Service {
    @Autowired
    MyBean myBean;
    .....
}

@Component("module2MyBean")
class MyBeanImpl implements MyBean{

}

不幸的是,Module1Service 和 Module2Service 都不包含@Resource 或@Qualifier。因此,当我尝试 bootstrap Module3.

时出现 NonUniqueBeanDefinition 异常

有什么方法可以在不对 Module1 或 Module2 进行任何更改的情况下避免此异常?

您是否依赖于 Module Service 或 Module2Service,如果不是,您可以使用 context:exclude-filter 讨论 here