kylixs opened a new issue #272:
URL: https://github.com/apache/dubbo-samples/issues/272


   The direct problem is that the zipkin `TracingFilter` failed to inject the 
brave.Tracer instance (ie the bean named 'tracing') when the greeting-service 
app was started.
   
   After analyzing the initialization process of TracingFilter, it is found 
that it uses `com.alibaba.spring.util.BeanFactoryUtils#getOptionalBean` to find 
the required tracing bean, and this method **will only find the bean that has 
been initialized and will not initialize a new instance.**
   
   Compared with 2.7.7/2.7.8, found this change from 2.7.8. In 2.7.7 and 
before, `BeanFactoryUtils#getOptionalBean` will auto create new instance.
   
   In 2.7.7 which depends on  `spring-context-support:1.0.6`:
   ```
       public static <T> List<T> getBeans(ListableBeanFactory beanFactory, 
String[] beanNames, Class<T> beanType) {
   
           if (isEmpty(beanNames)) {
               return emptyList();
           }
   
           String[] allBeanNames = 
beanNamesForTypeIncludingAncestors(beanFactory, beanType);
   
           List<T> beans = new ArrayList<T>(beanNames.length);
   
           for (String beanName : beanNames) {
               if (containsElement(allBeanNames, beanName)) {
                   beans.add(beanFactory.getBean(beanName, beanType));
               }
           }
   
           return unmodifiableList(beans);
       }
   ```
   
   In 2.7.8  which depends on `spring-context-support:1.0.8`:
   ```java
       public static <T> List<T> getBeans(ListableBeanFactory beanFactory, 
String[] beanNames, Class<T> beanType) {
   
           if (isEmpty(beanNames)) {
               return emptyList();
           }
   
           // Issue : 
https://github.com/alibaba/spring-context-support/issues/20
           String[] allBeanNames = 
beanNamesForTypeIncludingAncestors(beanFactory, beanType, true, false);
   
           List<T> beans = new ArrayList<T>(beanNames.length);
   
           for (String beanName : beanNames) {
               if (containsElement(allBeanNames, beanName)) {
                   beans.add(beanFactory.getBean(beanName, beanType));
               }
           }
   
           return unmodifiableList(beans);
       }
   ```
   
   Related issue: https://github.com/alibaba/spring-context-support/issues/20
   
   I think we can optimize the dependency of the filters, by using spring bean 
`depends-on` to solve the filter initialization order. Ensure that the filter 
bean is initialized before dubbo service/reference bean.
   
   


----------------------------------------------------------------
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.

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