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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to