This article is participating in the Java Theme Month – Java Debug Notes Event, see the event link for details

“Resolved” The bean ‘dubboConfigConfiguration. Single’ could not be registered. A bean with that name has already had been defined and overriding is disabled. Exception resolution

An overview of the

Today’s Springboot project reported such an exception while integrating dubbo.

Abnormal description

***************************
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
Copy the code

As the picture shows:

Abnormal analysis

This is actually a problem with the Dubbo version.

Dubbo version before 2.6.5 is implemented using DubboConfigConfigurationSelector ImportSelector returns the class name to load

But after the 2.6.8, is implemented using DubboConfigConfigurationRegistrar ImportBeanDefinitionRegistrar using Spring load utility class registration

Preliminary judgment DubboConfigConfigurationRegistrar during registration allow – bean – definition – overriding value is false, the loop regiest when an exception is thrown

DefaultListableBeanFactory allowBeanDefinitionOverriding value defaults to true but in SpringApplication assignment, when not configure this parameter can be set to false

Therefore, manually set the value.

The solution

Properties by adding:

spring.main.allow-bean-definition-overriding=true
Copy the code

Yml works by adding:

main:
    allow-bean-definition-overriding: true
Copy the code