You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "mercyblitz (GitHub)" <gi...@apache.org> on 2019/01/11 06:52:23 UTC

[GitHub] [incubator-dubbo] mercyblitz opened issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

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:

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

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] yxc023 commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "yxc023 (GitHub)" <gi...@apache.org>.
`spring.main.allow-bean-definition-overriding` 可以用来检测配置中的潜在问题.

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

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


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] mercyblitz commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "mercyblitz (GitHub)" <gi...@apache.org>.
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`.


[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] yxc023 commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "yxc023 (GitHub)" <gi...@apache.org>.
这个修改有问题, 原来的代码是正确的.

在 `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) { // Since 2.6.6 https://github.com/apache/incubator-dubbo/issues/3193
    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

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] mercyblitz commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "mercyblitz (GitHub)" <gi...@apache.org>.
It is a good discussion, I will change the implementation in Dubbo 2.7.2 and 2.6.7.

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] yxc023 commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "yxc023 (GitHub)" <gi...@apache.org>.
这个修改有问题, 原来的代码是正确的.

在 `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

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org

[GitHub] [incubator-dubbo] mercyblitz closed issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "mercyblitz (GitHub)" <gi...@apache.org>.
[ issue closed by mercyblitz ]

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org


[GitHub] [incubator-dubbo] mercyblitz commented on issue #3193: [Enhancement] Change the default behavior of @EnableDubboConfig.multiple()

Posted by "mercyblitz (GitHub)" <gi...@apache.org>.
Thanks for your advice, It does not matter, please take a look at https://github.com/apache/incubator-dubbo-spring-boot-project/issues/467.

[ Full content available at: https://github.com/apache/incubator-dubbo/issues/3193 ]
This message was relayed via gitbox.apache.org for notifications@dubbo.apache.org