手册

eip-assembly引入新增模块注意事项-bean重复问题

284
廖沅静
2023-03-15 15:48:14
分享链接


问题现象:

新增一个模块(pay),该模块依赖base模块,在五合一(assembly)引入该模块


启动assembly模块出现报错

bean name 'contextUtil' for bean class [com.hotent.uc.api.impl.util.ContextUtil] conflicts with existing, non-compatible bean definition of same name and class [com.hotent.uc.util.ContextUtil]


以上问题出现报错原因是:bean重复问题

1.pay模块的启动类跟assembly启动类名称不一致(如:PayApplication)

2.pay模块里面注解扫描了com.hotent.uc.api.impl


问题原因说明:

主要是@Configuration引起,当该类配置了@Configuration注解,此时若
容器里面没有payApplication这个bean时,该配置会生效,进而扫描com.hotent.*,因此会报bean重复问题。这也是引入uc,bpm模块为什么没有报错,因为现有模块的启动类名跟assembly一样是Application



解决方案:

方法一(建议使用):

修改新增模块启动类名PayApplication为Application(跟assembly模块的启动类名一致,使得新模块的启动类不是一个配置类)

方法二:

新模块的@Configuration改为@Configuration(“application”),这样当启动assembly时新增模块启动类也不会作为配置类生效

发表评论
评论通过审核后显示。