You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Enhancement] Change the default behavior of @EnableDubboConfig.multiple() #3193
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 bindingdubbo.protocol.name=dubbo
# Multiple configuration bindingdubbo.protcols.rest.name = rest
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.
Activity
Polish apache#3193 : [Enhancement] Change the default behavior of @En…
Polish apache#3193
[Enhancement] inline the source code of spring-context-support (#3225)
Polish apache#3193 : Change the default behavior of @EnableDubboConfi…
Polish /#3193 : Change the default behavior of @EnableDubboConfig.mul…
Enhancement and Bugfix in 2.7.1 ( Part 1 ) (#3670)
yxc023 commentedon Mar 19, 2019
这个修改有问题, 原来的代码是正确的.
在
DubboAutoConfiguration中, 有两个类SingleDubboConfigConfiguration,MultipleDubboConfigConfiguration当
dubbo.config.multiple = true, 这两个类都会被被当做configuration class引入因为这两个类上都有
@EnableDubboConfig注解, 而这个注解里有@Import(DubboConfigConfigurationRegistrar.class), 这个DubboConfigConfigurationRegistrar实现了ImportBeanDefinitionRegistrar所以这两个
configuration class引入时, 都会执行一遍DubboConfigConfigurationRegistrar.registerBeanDefinitions(), 不同点是这两个注解的
attributes.getBoolean("multiple")不同.正好在原
DubboConfigConfigurationRegistrar.registerBeanDefinitions()的实现中两次执行, 分别加载
DubboConfigConfiguration.Multiple.class和DubboConfigConfiguration.Single.class.而在修改后,
DubboConfigConfiguration.Multiple.class和DubboConfigConfiguration.Single.class每次都会加载一遍.这造成的 spring 容器里 bean definetion 的覆盖. 默认是不允许的, 只有设置
才行.
这次修改应该 revert
mercyblitz commentedon Mar 19, 2019
Thanks for your advice, It does not matter, please take a look at apache/dubbo-spring-boot-project#467.
yxc023 commentedon Mar 19, 2019
spring.main.allow-bean-definition-overriding可以用来检测配置中的潜在问题.dubbo 作为一个接入 spring 的一个组件, 更改了 spring 的全局配置, 看上去也不是很合适.
原来的实现并没有问题, 还是建议 revert.
mercyblitz commentedon Mar 19, 2019
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.Multiplestill 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 attributeallowBeanDefinitionOverridinginorg.springframework.beans.factory.support.DefaultListableBeanFactory, whose default value istrue.mercyblitz commentedon Mar 19, 2019
It is a good discussion, I will change the implementation in Dubbo 2.7.2 and 2.6.7.
fix default setting (#4955)
eternal5 commentedon Nov 25, 2019
只能通过设定spring.main.allow-bean-definition-overriding为true来解决这个问题吗? 还有其他方式吗(不升级dubbo版本)?