com.alibaba.dubbo.config.annotation.Reference Java Examples
The following examples show how to use
com.alibaba.dubbo.config.annotation.Reference.
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: AnnotationUtils.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
public static String resolveInterfaceName(Reference reference, Class<?> defaultInterfaceClass) throws IllegalStateException { String interfaceName; if (!"".equals(reference.interfaceName())) { interfaceName = reference.interfaceName(); } else if (!void.class.equals(reference.interfaceClass())) { interfaceName = reference.interfaceClass().getName(); } else if (defaultInterfaceClass.isInterface()) { interfaceName = defaultInterfaceClass.getName(); } else { throw new IllegalStateException( "The @Reference undefined interfaceClass or interfaceName, and the type " + defaultInterfaceClass.getName() + " is not a interface."); } return interfaceName; }
Example #2
Source File: InjectAnnotationBeanPostProcessor.java From spring-boot-starter-dubbo with Apache License 2.0 | 6 votes |
private static String resolveInterfaceName(Reference reference, Class<?> beanClass) throws IllegalStateException { String interfaceName; if (!"".equals(reference.interfaceName())) { interfaceName = reference.interfaceName(); } else if (!void.class.equals(reference.interfaceClass())) { interfaceName = reference.interfaceClass().getName(); } else if (beanClass.isInterface()) { interfaceName = beanClass.getName(); } else { throw new IllegalStateException( "The @Reference undefined interfaceClass or interfaceName, and the property type " + beanClass.getName() + " is not a interface."); } return interfaceName; }
Example #3
Source File: ReferenceAnnotationBeanPostProcessor.java From dubbo-2.6.5 with Apache License 2.0 | 6 votes |
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: CompensableBeanConfigValidator.java From ByteTCC with GNU Lesser General Public License v3.0 | 6 votes |
@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 #5
Source File: ReferenceAnnotationBeanPostProcessor.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Override protected String buildInjectedObjectCacheKey(Reference reference, Object bean, String beanName, Class<?> injectedType, InjectionMetadata.InjectedElement injectedElement) { String key = buildReferencedBeanName(reference, injectedType) + "#source=" + (injectedElement.getMember()) + "#attributes=" + AnnotationUtils.getAttributes(reference,getEnvironment(),true); return key; }
Example #6
Source File: DubboReferenceInjector.java From nano-framework with Apache License 2.0 | 5 votes |
@Override public void injectMembers(final T instance) { try { final Reference reference = field.getAnnotation(Reference.class); final ReferenceConfig<?> refer = new ReferenceConfig<>(reference); refer.setCheck(reference.check()); refer.setInterface(field.getType()); final Object newInstance = ReferenceConfigCache.getCache().get(refer); field.set(instance, newInstance); } catch (final IllegalAccessException e) { throw (Error) new IllegalAccessError(e.getMessage()).initCause(e); } }
Example #7
Source File: DubboConsumerAutoConfiguration.java From dubbo-spring-boot-starter with Apache License 2.0 | 5 votes |
/** * 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 #8
Source File: DubboReferenceInterceptor.java From nano-framework with Apache License 2.0 | 5 votes |
@Override protected void inject(final MethodInvocation invocation, final Method method, final Class<?> returnType) throws Throwable { final Reference reference = method.getAnnotation(Reference.class); final ReferenceConfig<?> refer = new ReferenceConfig<>(reference); refer.setCheck(reference.check()); refer.setInterface(returnType); final Object newInstance = ReferenceConfigCache.getCache().get(refer); setInstance(invocation.getThis(), method, returnType, newInstance); }
Example #9
Source File: ServiceBeanNameBuilderTest.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@Test public void testReferenceAnnotation() { Reference reference = AnnotationUtils.getAnnotation(ReflectionUtils.findField(ServiceBeanNameBuilderTest.class, "INTERFACE_CLASS"), Reference.class); ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(reference, INTERFACE_CLASS, environment); Assert.assertEquals(BEAN_NAME, builder.build()); }
Example #10
Source File: ReferenceBeanBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 5 votes |
@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 #11
Source File: ReferenceConfig.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public ReferenceConfig(Reference reference) { appendAnnotation(Reference.class, reference); }
Example #12
Source File: InjectAnnotationBeanPostProcessor.java From spring-boot-starter-dubbo with Apache License 2.0 | 4 votes |
protected ReferenceFieldElement(Field field, Reference reference) { super(field, null); this.field = field; this.reference = reference; }
Example #13
Source File: InjectAnnotationBeanPostProcessor.java From spring-boot-starter-dubbo with Apache License 2.0 | 4 votes |
protected ReferenceMethodElement(Method method, PropertyDescriptor pd, Reference reference) { super(method, pd); this.method = method; this.reference = reference; }
Example #14
Source File: ReferenceConfig.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceConfig(Reference reference) { appendAnnotation(Reference.class, reference); }
Example #15
Source File: ReferenceBean.java From dubbox-hystrix with Apache License 2.0 | 4 votes |
public ReferenceBean(Reference reference) { super(reference); }
Example #16
Source File: ReferenceConfig.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceConfig(Reference reference) { appendAnnotation(Reference.class, reference); }
Example #17
Source File: ReferenceBean.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceBean(Reference reference) { super(reference); }
Example #18
Source File: InjectAnnotationBeanPostProcessor.java From spring-boot-starter-dubbo with Apache License 2.0 | 4 votes |
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 #19
Source File: ReferenceBean.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceBean(Reference reference) { super(reference); }
Example #20
Source File: ReferenceConfig.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public ReferenceConfig(Reference reference) { // 解析@Reference配置=》 appendAnnotation(Reference.class, reference); }
Example #21
Source File: ReferenceBean.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceBean(Reference reference) { super(reference); }
Example #22
Source File: ReferenceConfig.java From dubbox with Apache License 2.0 | 4 votes |
public ReferenceConfig(Reference reference) { appendAnnotation(Reference.class, reference); }
Example #23
Source File: DubboReferenceModule.java From nano-framework with Apache License 2.0 | 4 votes |
@Override public void configure(final Binder binder) { binder.bindInterceptor(Matchers.any(), Matchers.annotatedWith(Reference.class), new DubboReferenceInterceptor()); }
Example #24
Source File: HelloWorldProxy.java From nano-framework with Apache License 2.0 | 4 votes |
@Inject @Reference(check = false, url = "dubbo://" + SERVER + "/org.nanoframework.extension.dubbo.service.HelloWorldService") public HelloWorldService getHelloWorldService() { return helloWorldService; }
Example #25
Source File: HelloWorldProxy.java From nano-framework with Apache License 2.0 | 4 votes |
@Inject @Reference(check = false, url = "dubbo://" + SERVER + "/org.nanoframework.extension.dubbo.service.HelloWorld2Service") public HelloWorld2Service getHelloWorld2Service() { return helloWorld2Service; }
Example #26
Source File: ReferenceBeanBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@Override protected String resolveMonitorConfigBeanName(Reference annotation) { return annotation.monitor(); }
Example #27
Source File: ReferenceAnnotationBeanPostProcessor.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
@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 #28
Source File: ServiceBeanNameBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
private ServiceBeanNameBuilder(Reference reference, Class<?> interfaceClass, Environment environment) { this(resolveInterfaceName(reference, interfaceClass), environment); this.group(reference.group()); this.version(reference.version()); }
Example #29
Source File: ServiceBeanNameBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
public static ServiceBeanNameBuilder create(Reference reference, Class<?> interfaceClass, Environment environment) { return new ServiceBeanNameBuilder(reference, interfaceClass, environment); }
Example #30
Source File: ReferenceBeanBuilder.java From dubbo-2.6.5 with Apache License 2.0 | 4 votes |
private ReferenceBeanBuilder(Reference annotation, ClassLoader classLoader, ApplicationContext applicationContext) { super(annotation, classLoader, applicationContext); }