Skip to content

[Enhancement] Change the default behavior of @EnableDubboConfig.multiple() #3193

Closed

Description

@mercyblitz

The default value of @EnableDubboConfig#multiple() method attribute is false, and it will be changed to true, thus single and multiple configuration bindings work at the same time, e.g:

# Single configuration binding
dubbo.protocol.name=dubbo
# Multiple configuration binding
dubbo.protcols.rest.name = rest

Activity

  1. added this to the 2.6.6 milestone on Jan 11, 2019
  2. self-assigned this
    on Jan 11, 2019
  3. added a commit that references this issue on Jan 16, 2019
  4. added a commit that references this issue on Jan 26, 2019
  5. added 2 commits that reference this issue on Mar 14, 2019
  6. modified the milestones: 2.6.6, 2.7.1 on Mar 15, 2019
  7. yxc023 commented on Mar 19, 2019

    @yxc023

    这个修改有问题, 原来的代码是正确的.

    在 DubboAutoConfiguration 中, 有两个类 SingleDubboConfigConfiguration, MultipleDubboConfigConfiguration

    当 dubbo.config.multiple = true, 这两个类都会被被当做 configuration class 引入

    因为这两个类上都有 @EnableDubboConfig 注解, 而这个注解里有 @Import(DubboConfigConfigurationRegistrar.class) , 这个 DubboConfigConfigurationRegistrar 实现了 ImportBeanDefinitionRegistrar

    所以这两个 configuration class 引入时, 都会执行一遍 DubboConfigConfigurationRegistrar.registerBeanDefinitions(), 不同点是
    这两个注解的 attributes.getBoolean("multiple") 不同.

    正好在原 DubboConfigConfigurationRegistrar.registerBeanDefinitions() 的实现中

    if (multiple) {
        registerBeans(registry, DubboConfigConfiguration.Multiple.class);
    } else {
        registerBeans(registry, DubboConfigConfiguration.Single.class);
    }
    

    两次执行, 分别加载 DubboConfigConfiguration.Multiple.class 和 DubboConfigConfiguration.Single.class.

    而在修改后, DubboConfigConfiguration.Multiple.class 和 DubboConfigConfiguration.Single.class 每次都会加载一遍.

    这造成的 spring 容器里 bean definetion 的覆盖. 默认是不允许的, 只有设置

    spring:
      main:
        allow-bean-definition-overriding: true
    

    才行.

    这次修改应该 revert

  8. mercyblitz commented on Mar 19, 2019

    @mercyblitz
    ContributorAuthor

    Thanks for your advice, It does not matter, please take a look at apache/dubbo-spring-boot-project#467.

  9. yxc023 commented on Mar 19, 2019

    @yxc023

    spring.main.allow-bean-definition-overriding 可以用来检测配置中的潜在问题.

    dubbo 作为一个接入 spring 的一个组件, 更改了 spring 的全局配置, 看上去也不是很合适.

    原来的实现并没有问题, 还是建议 revert.

  10. mercyblitz commented on Mar 19, 2019

    @mercyblitz
    ContributorAuthor

    However, We can't prevent this problem even if revert. Considering this scenario: if an application annotated @EnableDubboConfig(multiple=true) twice and @EnableDubboConfig(multiple=false) once, DubboConfigConfiguration.Multiple still will be registered two times, thus the natural reason is Spring Boot 2.1 changing the default behavior of bean definition, it's to gild the lily. Please see the attribute allowBeanDefinitionOverriding in org.springframework.beans.factory.support.DefaultListableBeanFactory, whose default value is true.

  11. mercyblitz commented on Mar 19, 2019

    @mercyblitz
    ContributorAuthor

    It is a good discussion, I will change the implementation in Dubbo 2.7.2 and 2.6.7.

  12. added a commit that references this issue on Sep 10, 2019
  13. eternal5 commented on Nov 25, 2019

    @eternal5

    只能通过设定spring.main.allow-bean-definition-overriding为true来解决这个问题吗? 还有其他方式吗(不升级dubbo版本)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions