com.alibaba.dubbo.config.spring.ReferenceBean Java Examples

The following examples show how to use com.alibaba.dubbo.config.spring.ReferenceBean. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompensableBeanConfigValidator.java    From ByteTCC with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
	Class<?> targetClass = AopUtils.getTargetClass(bean);
	if (targetClass == null) {
		return bean;
	}

	Compensable compensable = targetClass.getAnnotation(Compensable.class);
	if (compensable == null) {
		return bean;
	}

	Field[] fields = targetClass.getDeclaredFields();
	for (int i = 0; fields != null && i < fields.length; i++) {
		Field field = fields[i];
		Reference reference = field.getAnnotation(Reference.class);
		if (reference == null) {
			continue;
		}

		ReferenceBean referenceConfig = new ReferenceBean(reference);
		this.validateReferenceBean(beanName, referenceConfig);
	}

	return bean;
}
 
Example #2
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private InvocationHandler buildInvocationHandler(String referencedBeanName, ReferenceBean referenceBean) {

        ReferenceBeanInvocationHandler handler = localReferenceBeanInvocationHandlerCache.get(referencedBeanName);

        if (handler == null) {
            handler = new ReferenceBeanInvocationHandler(referenceBean);
        }

        if (applicationContext.containsBean(referencedBeanName)) { // Is local @Service Bean or not ?
            // ReferenceBeanInvocationHandler's initialization has to wait for current local @Service Bean has been exported.
            localReferenceBeanInvocationHandlerCache.put(referencedBeanName, handler);
        } else {
            // Remote Reference Bean should initialize immediately 初始化@Reference的bean
            handler.init();
        }

        return handler;
    }
 
Example #3
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
private ReferenceBean buildReferenceBeanIfAbsent(String referencedBeanName, Reference reference,
                                                 Class<?> referencedType, ClassLoader classLoader)
        throws Exception {

    ReferenceBean<?> referenceBean = referenceBeanCache.get(referencedBeanName);

    if (referenceBean == null) {
        ReferenceBeanBuilder beanBuilder = ReferenceBeanBuilder
                .create(reference, classLoader, applicationContext)
                .interfaceClass(referencedType);
        referenceBean = beanBuilder.build();
        referenceBeanCache.put(referencedBeanName, referenceBean);
    }

    return referenceBean;
}
 
Example #4
Source File: InjectAnnotationBeanPostProcessor.java    From spring-boot-starter-dubbo with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() throws Exception {

    for (ReferenceBean<?> referenceBean : referenceBeansCache.values()) {
        if (logger.isInfoEnabled()) {
            logger.info(referenceBean + " was destroying!");
        }
        referenceBean.destroy();
    }

    injectionMetadataCache.clear();
    referenceBeansCache.clear();

    if (logger.isInfoEnabled()) {
        logger.info(getClass() + " was destroying!");
    }

}
 
Example #5
Source File: DubboNamespaceHandler.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
    public void init() {
//        xml配置解析=》
        registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
        registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
        registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
        registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
        registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
        registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
        registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
        registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
        registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
//        annotation解析<dubbo:annotation package="" />xml配置=》
        registerBeanDefinitionParser("annotation", new AnnotationBeanDefinitionParser());
    }
 
Example #6
Source File: DubboNamespaceHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void init() {
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
Example #7
Source File: DubboNamespaceHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void init() {
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
Example #8
Source File: DubboNamespaceHandler.java    From dubbo3 with Apache License 2.0 5 votes vote down vote up
public void init() {
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
Example #9
Source File: DubboConsumerAutoConfiguration.java    From dubbo-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
/**
 * init consumer bean
 *
 * @param interfaceClazz interfaceClazz
 * @param reference reference
 * @return ReferenceBean<T>
 * @throws BeansException BeansException
 */
private <T> ReferenceBean<T> getConsumerBean(String beanName, Field field, Reference reference)
    throws BeansException {
  ReferenceBean<T> referenceBean = new ReferenceBean<T>(reference);
  if ((reference.interfaceClass() == null || reference.interfaceClass() == void.class)
      && (reference.interfaceName() == null || "".equals(reference.interfaceName()))) {
    referenceBean.setInterface(field.getType());
  }

  Environment environment = this.applicationContext.getEnvironment();
  String application = reference.application();
  referenceBean.setApplication(this.parseApplication(application, this.properties, environment,
      beanName, field.getName(), "application", application));
  String module = reference.module();
  referenceBean.setModule(this.parseModule(module, this.properties, environment, beanName,
      field.getName(), "module", module));
  String[] registries = reference.registry();
  referenceBean.setRegistries(this.parseRegistries(registries, this.properties, environment,
      beanName, field.getName(), "registry"));
  String monitor = reference.monitor();
  referenceBean.setMonitor(this.parseMonitor(monitor, this.properties, environment, beanName,
      field.getName(), "monitor", monitor));
  String consumer = reference.consumer();
  referenceBean.setConsumer(this.parseConsumer(consumer, this.properties, environment, beanName,
      field.getName(), "consumer", consumer));

  referenceBean.setApplicationContext(DubboConsumerAutoConfiguration.this.applicationContext);
  return referenceBean;
}
 
Example #10
Source File: DubboNamespaceHandler.java    From dubbox-hystrix with Apache License 2.0 5 votes vote down vote up
public void init() {
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
Example #11
Source File: DubboNamespaceHandler.java    From dubbox with Apache License 2.0 5 votes vote down vote up
public void init() {
 registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
    registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
    registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
    registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
    registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
    registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
    registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
    registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
    registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
    registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
}
 
Example #12
Source File: ReferenceBeanBuilder.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Override
protected void preConfigureBean(Reference reference, ReferenceBean referenceBean) {
    Assert.notNull(interfaceClass, "The interface class must set first!");
    DataBinder dataBinder = new DataBinder(referenceBean);
    // Register CustomEditors for special fields
    dataBinder.registerCustomEditor(String.class, "filter", new StringTrimmerEditor(true));
    dataBinder.registerCustomEditor(String.class, "listener", new StringTrimmerEditor(true));
    dataBinder.registerCustomEditor(Map.class, "parameters", new PropertyEditorSupport() {

        public void setAsText(String text) throws java.lang.IllegalArgumentException {
            // Trim all whitespace
            String content = StringUtils.trimAllWhitespace(text);
            if (!StringUtils.hasText(content)) { // No content , ignore directly
                return;
            }
            // replace "=" to ","
            content = StringUtils.replace(content, "=", ",");
            // replace ":" to ","
            content = StringUtils.replace(content, ":", ",");
            // String[] to Map
            Map<String, String> parameters = CollectionUtils.toStringMap(commaDelimitedListToStringArray(content));
            setValue(parameters);
        }
    });

    // Bind annotation attributes
    dataBinder.bind(new AnnotationPropertyValuesAdapter(reference, applicationContext.getEnvironment(), IGNORE_FIELD_NAMES));

}
 
Example #13
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void cacheInjectedReferenceBean(ReferenceBean referenceBean,
                                        InjectionMetadata.InjectedElement injectedElement) {
    if (injectedElement.getMember() instanceof Field) {
        injectedFieldReferenceBeanCache.put(injectedElement, referenceBean);
    } else if (injectedElement.getMember() instanceof Method) {
        injectedMethodReferenceBeanCache.put(injectedElement, referenceBean);
    }
}
 
Example #14
Source File: ReferenceBeanBuilder.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
protected ReferenceBean doBuild() {
    return new ReferenceBean<Object>();
}
 
Example #15
Source File: ReferenceAnnotationBeanPostProcessorTest.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
/**
 * Test on {@link ReferenceAnnotationBeanPostProcessor#getReferenceBeans()}
 */
@Test
public void testGetReferenceBeans() {

    ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
            ReferenceAnnotationBeanPostProcessor.class);

    Collection<ReferenceBean<?>> referenceBeans = beanPostProcessor.getReferenceBeans();

    Assert.assertEquals(1, referenceBeans.size());

    ReferenceBean<?> referenceBean = referenceBeans.iterator().next();

    TestBean testBean = context.getBean(TestBean.class);

    Assert.assertNotNull(referenceBean.get());

}
 
Example #16
Source File: InjectAnnotationBeanPostProcessor.java    From spring-boot-starter-dubbo with Apache License 2.0 4 votes vote down vote up
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)
                    .interfaceClass(referenceClass);

            referenceBean = beanBuilder.build();

            referenceBeansCache.putIfAbsent(referenceBeanCacheKey, referenceBean);

        }


        return referenceBean.get();
    }
 
Example #17
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private ReferenceBeanInvocationHandler(ReferenceBean referenceBean) {
    this.referenceBean = referenceBean;
}
 
Example #18
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
private Object buildProxy(String referencedBeanName, ReferenceBean referenceBean, Class<?> injectedType) {
//        构建执行handler
        InvocationHandler handler = buildInvocationHandler(referencedBeanName, referenceBean);
        Object proxy = Proxy.newProxyInstance(getClassLoader(), new Class[]{injectedType}, handler);
        return proxy;
    }
 
Example #19
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
@Override
    protected Object doGetInjectedBean(Reference reference, Object bean, String beanName, Class<?> injectedType,
                                       InjectionMetadata.InjectedElement injectedElement) throws Exception {

//        引用的bean的名字也是指定接口的权限定名=》
        String referencedBeanName = buildReferencedBeanName(reference, injectedType);

        ReferenceBean referenceBean = buildReferenceBeanIfAbsent(referencedBeanName, reference, injectedType, getClassLoader());

        cacheInjectedReferenceBean(referenceBean, injectedElement);

//        返回代理对象
        Object proxy = buildProxy(referencedBeanName, referenceBean, injectedType);

        return proxy;
    }
 
Example #20
Source File: CompensableBeanConfigValidator.java    From ByteTCC with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public void validateReferenceBean(String beanId, ReferenceBean referenceBean) throws BeansException {
	Integer retries = referenceBean.getRetries();
	String loadBalance = referenceBean.getLoadbalance();
	String cluster = referenceBean.getCluster();
	String filter = referenceBean.getFilter();
	String group = referenceBean.getGroup();

	if (StringUtils.equals(group, "x-bytetcc") == false
			&& StringUtils.trimToEmpty(group).startsWith("x-bytetcc-") == false) {
		throw new FatalBeanException(String.format(
				"The value of attr 'group'(beanId= %s) should be 'x-bytetcc' or starts with 'x-bytetcc-'.", beanId));
	} else if (retries != null && retries >= 0) {
		throw new FatalBeanException(String.format("The value of attr 'retries'(beanId= %s) should be '-1'.", beanId));
	} else if (this.statefully && StringUtils.equals(loadBalance, "bytetcc") == false) {
		throw new FatalBeanException(
				String.format("The value of attr 'loadbalance'(beanId= %s) should be 'bytetcc'.", beanId));
	} else if (StringUtils.equals("failfast", cluster) == false) {
		throw new FatalBeanException(
				String.format("The value of attribute 'cluster' (beanId= %s) must be 'failfast'.", beanId));
	} else if (filter == null) {
		throw new FatalBeanException(String
				.format("The value of attr 'filter'(beanId= %s) must be java.lang.String and cannot be null.", beanId));
	} else {
		String filterValue = StringUtils.trimToEmpty(filter);
		String[] filterArray = filterValue.split("\\s*,\\s*");

		int filters = 0, index = -1;
		for (int i = 0; i < filterArray.length; i++) {
			String element = filterArray[i];
			boolean filterEquals = StringUtils.equalsIgnoreCase("bytetcc", element);
			index = filterEquals ? i : index;
			filters = filterEquals ? filters + 1 : filters;
		}

		if (filters != 1) {
			throw new FatalBeanException(
					String.format("The value of attr 'filter'(beanId= %s) should contains 'bytetcc'.", beanId));
		} else if (index != (filterArray.length - 1)) {
			throw new FatalBeanException(String.format("The last filter of bean(beanId= %s) should be 'bytetcc'.", beanId));
		}
	}

	String clazzName = referenceBean.getInterface();
	ClassLoader cl = Thread.currentThread().getContextClassLoader();

	Class<?> clazz = null;
	try {
		clazz = cl.loadClass(clazzName);
	} catch (Exception ex) {
		throw new FatalBeanException(String.format("Cannot load class %s.", clazzName));
	}

	Method[] methodArray = clazz.getMethods();
	for (int i = 0; i < methodArray.length; i++) {
		Method method = methodArray[i];
		boolean declared = false;
		Class<?>[] exceptionTypeArray = method.getExceptionTypes();
		for (int j = 0; j < exceptionTypeArray.length; j++) {
			Class<?> exceptionType = exceptionTypeArray[j];
			if (RemotingException.class.isAssignableFrom(exceptionType)) {
				declared = true;
				break;
			}
		}

		if (declared == false) {
			// throw new FatalBeanException(String.format(
			// "The remote call method(%s) must be declared to throw a remote exception:
			// org.bytesoft.compensable.RemotingException!",
			// method));
			logger.warn("The remote call method({}) should be declared to throw a remote exception: {}!", method,
					RemotingException.class.getName());
		}

	}

}
 
Example #21
Source File: ReferenceBeanBuilder.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
@Override
protected void postConfigureBean(Reference annotation, ReferenceBean bean) throws Exception {

    bean.setApplicationContext(applicationContext);

    configureInterface(annotation, bean);

    configureConsumerConfig(annotation, bean);

    bean.afterPropertiesSet();

}
 
Example #22
Source File: ReferenceAnnotationBeanPostProcessorTest.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
@Test
public void testGetInjectedFieldReferenceBeanMap() {

    ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
            ReferenceAnnotationBeanPostProcessor.class);


    Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
            beanPostProcessor.getInjectedFieldReferenceBeanMap();

    Assert.assertEquals(1, referenceBeanMap.size());

    for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) {

        InjectionMetadata.InjectedElement injectedElement = entry.getKey();

        Assert.assertEquals("com.alibaba.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement",
                injectedElement.getClass().getName());

        ReferenceBean<?> referenceBean = entry.getValue();

        Assert.assertEquals("2.5.7", referenceBean.getVersion());
        Assert.assertEquals("dubbo://127.0.0.1:12345", referenceBean.getUrl());

    }

}
 
Example #23
Source File: ReferenceAnnotationBeanPostProcessorTest.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
@Test
public void testGetInjectedMethodReferenceBeanMap() {

    ReferenceAnnotationBeanPostProcessor beanPostProcessor = context.getBean(BEAN_NAME,
            ReferenceAnnotationBeanPostProcessor.class);


    Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> referenceBeanMap =
            beanPostProcessor.getInjectedMethodReferenceBeanMap();

    Assert.assertEquals(2, referenceBeanMap.size());

    for (Map.Entry<InjectionMetadata.InjectedElement, ReferenceBean<?>> entry : referenceBeanMap.entrySet()) {

        InjectionMetadata.InjectedElement injectedElement = entry.getKey();

        Assert.assertEquals("com.alibaba.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedMethodElement",
                injectedElement.getClass().getName());

        ReferenceBean<?> referenceBean = entry.getValue();

        Assert.assertEquals("2.5.7", referenceBean.getVersion());
        Assert.assertEquals("dubbo://127.0.0.1:12345", referenceBean.getUrl());

    }

}
 
Example #24
Source File: ReferenceBeanBuilder.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
private void configureConsumerConfig(Reference reference, ReferenceBean<?> referenceBean) {

        String consumerBeanName = reference.consumer();

        ConsumerConfig consumerConfig = getOptionalBean(applicationContext, consumerBeanName, ConsumerConfig.class);

        referenceBean.setConsumer(consumerConfig);

    }
 
Example #25
Source File: ReferenceBeanBuilder.java    From dubbo-2.6.5 with Apache License 2.0 3 votes vote down vote up
private void configureInterface(Reference reference, ReferenceBean referenceBean) {

        Class<?> interfaceClass = reference.interfaceClass();

        if (void.class.equals(interfaceClass)) {

            interfaceClass = null;

            String interfaceClassName = reference.interfaceName();

            if (StringUtils.hasText(interfaceClassName)) {
                if (ClassUtils.isPresent(interfaceClassName, classLoader)) {
                    interfaceClass = ClassUtils.resolveClassName(interfaceClassName, classLoader);
                }
            }

        }

        if (interfaceClass == null) {
            interfaceClass = this.interfaceClass;
        }

        Assert.isTrue(interfaceClass.isInterface(),
                "The class of field or method that was annotated @Reference is not an interface!");

        referenceBean.setInterface(interfaceClass);

    }
 
Example #26
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * Gets all beans of {@link ReferenceBean}
 *
 * @return non-null read-only {@link Collection}
 * @since 2.5.9
 */
public Collection<ReferenceBean<?>> getReferenceBeans() {
    return referenceBeanCache.values();
}
 
Example #27
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * Get {@link ReferenceBean} {@link Map} in injected method.
 *
 * @return non-null {@link Map}
 * @since 2.5.11
 */
public Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> getInjectedMethodReferenceBeanMap() {
    return Collections.unmodifiableMap(injectedMethodReferenceBeanCache);
}
 
Example #28
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 2 votes vote down vote up
/**
 * Get {@link ReferenceBean} {@link Map} in injected field.
 *
 * @return non-null {@link Map}
 * @since 2.5.11
 */
public Map<InjectionMetadata.InjectedElement, ReferenceBean<?>> getInjectedFieldReferenceBeanMap() {
    return Collections.unmodifiableMap(injectedFieldReferenceBeanCache);
}