You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/03/03 08:15:47 UTC
[GitHub] [dubbo] hieastz opened a new issue #9736: 致各位开发者的一个issue
hieastz opened a new issue #9736:
URL: https://github.com/apache/dubbo/issues/9736
首先,非常谢谢你们在这内卷的时代仍然在给dubbo写bug。
事情是这样的。今天进行dubbo的更新,其实只是个小版本升级,从2.7.3升级到2.7.8。
然后发现在dubbo filter中的使用setter方式注入的spring bean没有注入到,切回老版本测试是好用的。
开始分析代码。主要是 `SpringExtensionFactory.getExtension`。
2.7.3代码如下:
```
@Override
@SuppressWarnings("unchecked")
public <T> T getExtension(Class<T> type, String name) {
//SPI should be get from SpiExtensionFactory
if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
return null;
}
for (ApplicationContext context : CONTEXTS) {
if (context.containsBean(name)) {
Object bean = context.getBean(name);
if (type.isInstance(bean)) {
return (T) bean;
}
}
}
logger.warn("No spring extension (bean) named:" + name + ", try to find an extension (bean) of type " + type.getName());
if (Object.class == type) {
return null;
}
for (ApplicationContext context : CONTEXTS) {
try {
return context.getBean(type);
} catch (NoUniqueBeanDefinitionException multiBeanExe) {
logger.warn("Find more than 1 spring extensions (beans) of type " + type.getName() + ", will stop auto injection. Please make sure you have specified the concrete parameter type and there's only one extension of that type.");
} catch (NoSuchBeanDefinitionException noBeanExe) {
if (logger.isDebugEnabled()) {
logger.debug("Error when get spring extension(bean) for type:" + type.getName(), noBeanExe);
}
}
}
logger.warn("No spring extension (bean) named:" + name + ", type:" + type.getName() + " found, stop get bean.");
return null;
}
```
2.7.8代码如下:
```
@Override
@SuppressWarnings("unchecked")
public <T> T getExtension(Class<T> type, String name) {
//SPI should be get from SpiExtensionFactory
if (type.isInterface() && type.isAnnotationPresent(SPI.class)) {
return null;
}
for (ApplicationContext context : CONTEXTS) {
T bean = BeanFactoryUtils.getOptionalBean(context, name, type);
if (bean != null) {
return bean;
}
}
//logger.warn("No spring extension (bean) named:" + name + ", try to find an extension (bean) of type " + type.getName());
return null;
}
```
总结一下,就是2.7.3版本具有容错性,当名称匹配不上时会按入参类型给返回个。
2.7.8版本会严格匹配bean的名称。具体的代码不贴了。
前提是我的setter是按照类名规范定义的。
最后发现用Spring的 `@EnableConfigurationProperties(Class.class)` 装配属性类,此时的bean名称是`@ConfigurationProperties.prefix-类全路径`。也怪自己才疏学浅。
我只想说,小版本升级应该是向前兼容的,而且按注入类型返回并没有不妥的问题。
我就想吐槽,天天改来改去有意思吗?就这么几行代码折腾不明白了?我看了变更记录,一个类改来改去的。拿这点时间去创造新的东西不好吗?实在不行回家配老婆孩子父母啊。
求求你们别折腾了。求求你们别折腾了。求求你们别折腾了。
越改问题越多。越改问题越多。越改问题越多。
吐槽完毕!就这样吧,开源都一个德行。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] chickenlj closed issue #9736: 致各位开发者的一个issue
Posted by GitBox <gi...@apache.org>.
chickenlj closed issue #9736:
URL: https://github.com/apache/dubbo/issues/9736
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] chickenlj commented on issue #9736: 致各位开发者的一个issue
Posted by GitBox <gi...@apache.org>.
chickenlj commented on issue #9736:
URL: https://github.com/apache/dubbo/issues/9736#issuecomment-1061632031
> 我就想吐槽,天天改来改去有意思吗?就这么几行代码折腾不明白了?我看了变更记录,一个类改来改去的。拿这点时间去创造新的东西不好吗?实在不行回家配老婆孩子父母啊。
代表社区为版本行为调整带来使用体验表示歉意,同时非常欢迎多参与开源贡献代码与文档。
此 SpringExtensionFactory 加载逻辑在 2.7.x 版本中将维持现状,不打算再做新变更。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] xiaochangbai commented on issue #9736: 致各位开发者的一个issue
Posted by GitBox <gi...@apache.org>.
xiaochangbai commented on issue #9736:
URL: https://github.com/apache/dubbo/issues/9736#issuecomment-1060103838
字正腔圆
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org