dubbo Reference 注解属性 version



private Object buildReferenceBean(Reference reference, Class<?> referenceClass) throws Exception {

    String referenceBeanCacheKey = generateReferenceBeanCacheKey(reference, referenceClass);

    ReferenceBean<?> referenceBean = referenceBeansCache.get(referenceBeanCacheKey);

    if (referenceBean == null) {

        ReferenceBeanBuilder beanBuilder = ReferenceBeanBuilder
                .create(reference, classLoader, applicationContext)

        referenceBean = beanBuilder.build();

        referenceBeansCache.putIfAbsent(referenceBeanCacheKey, referenceBean);


    return referenceBean.get();

 * Generate a cache key of {@link ReferenceBean}
 * @param reference {@link Reference}
 * @param beanClass {@link Class}
 * @return
private static String generateReferenceBeanCacheKey(Reference reference, Class<?> beanClass) {

    String interfaceName = resolveInterfaceName(reference, beanClass);

    String key = reference.group() + "/" + interfaceName + ":" + reference.version();

    return key;



所以当service多个实现启用dubbo的时候要么区分版本号要么给实现加名称(Service :value)区分。


 * If the specified key is not already associated
 * with a value, associate it with the given value.
 * This is equivalent to
 *  <pre> {@code
 * if (!map.containsKey(key))
 *   return map.put(key, value);
 * else
 *   return map.get(key);
 * }</pre>
 * except that the action is performed atomically.
 * @implNote This implementation intentionally re-abstracts the
 * inappropriate default provided in {@code Map}.
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with the specified key, or
 *         {@code null} if there was no mapping for the key.
 *         (A {@code null} return can also indicate that the map
 *         previously associated {@code null} with the key,
 *         if the implementation supports null values.)
 * @throws UnsupportedOperationException if the {@code put} operation
 *         is not supported by this map
 * @throws ClassCastException if the class of the specified key or value
 *         prevents it from being stored in this map
 * @throws NullPointerException if the specified key or value is null,
 *         and this map does not permit null keys or values
 * @throws IllegalArgumentException if some property of the specified key
 *         or value prevents it from being stored in this map
 V putIfAbsent(K key, V value);




电子邮件地址不会被公开。 必填项已用*标注