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 2021/08/18 04:01:31 UTC

[GitHub] [dubbo] kylixs commented on issue #8504: 注解与JavaConfig与service group分组写法的迷惑?

kylixs commented on issue #8504:
URL: https://github.com/apache/dubbo/issues/8504#issuecomment-900794261


   这里涉及到Spring autowire的实现逻辑,具体可以调试一下代码:  org.springframework.beans.factory.support.DefaultListableBeanFactory#determineAutowireCandidate()
   
   如果不指定primary和priority,最后会尝试匹配beanName和fieldName/dependcyName,即如果fieldName和beanName相同就可以成功注入,如果不相同且存在多个候选bean则会报错。
   
   ```java
   	protected String determineAutowireCandidate(Map<String, Object> candidates, DependencyDescriptor descriptor) {
   		Class<?> requiredType = descriptor.getDependencyType();
   		String primaryCandidate = determinePrimaryCandidate(candidates, requiredType);
   		if (primaryCandidate != null) {
   			return primaryCandidate;
   		}
   		String priorityCandidate = determineHighestPriorityCandidate(candidates, requiredType);
   		if (priorityCandidate != null) {
   			return priorityCandidate;
   		}
   		// Fallback
   		for (Map.Entry<String, Object> entry : candidates.entrySet()) {
   			String candidateName = entry.getKey();
   			Object beanInstance = entry.getValue();
   			if ((beanInstance != null && this.resolvableDependencies.containsValue(beanInstance)) ||
   					matchesBeanName(candidateName, descriptor.getDependencyName())) {
   				return candidateName;
   			}
   		}
   		return null;
   	}
   ```
   
   


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