【已解决】The bean ‘dubboConfigConfiguration.Single’ could not be registered. A bean with that name has already been defined and overriding is disabled.异常解决

概述

今天的Springboot项目在集成dubbo的时候,报了这么一个异常。

异常描述

***************************
APPLICATION FAILED TO START
***************************

Description:

The bean 'dubboConfigConfiguration.Single' could not be registered. A bean with that name has already been defined and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

如图片所示:

【已解决】Dubbo版本升级引起的循环注册异常_异常解决

异常分析

这个其实是dubbo版本的一个问题。

dubbo版本在2.6.5之前是使用 DubboConfigConfigurationSelector 实现ImportSelector 返回类名称去加载的

而在2.6.8之后变了,是使用 DubboConfigConfigurationRegistrar 实现ImportBeanDefinitionRegistrar 使用Spring工具类注册加载的

初步判断DubboConfigConfigurationRegistrar在注册的时候allow-bean-definition-overriding 值为false,循环register的时候抛出异常

DefaultListableBeanFactory 中allowBeanDefinitionOverriding值默认为true 但是在SpringApplication 进行赋值,当没配置此参数时,会被设置成false

所以,手动设置该值即可解决。

解决方案

properties通过添加:

spring.main.allow-bean-definition-overriding=true

yml通过添加:

main:
allow-bean-definition-overriding: true