简体   繁体   中英

Spring unique bean - multiple modules

I'm working on Module3 which is dependent on Module1 and Module2.

Module1 has the following classes:

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

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

}

Module2 has the following classes:

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

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

}

Unfortunately, both Module1Service and Module2Service do not contain @Resource or @Qualifier. Because of this, I get NonUniqueBeanDefinition exception when I try to bootstrap Module3.

Is there any way I can avoid this exception without making any changes to Module1 or Module2?

您是否依赖Module1Service或Module2Service,如果不依赖,则可以使用context:exclude-filter 这里讨论。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM