Search in sources :

Example 1 with Service

use of org.apache.dubbo.config.annotation.Service in project dubbo by alibaba.

the class AnnotationUtilsTest method assertADeclaredAnnotations.

private void assertADeclaredAnnotations(List<Annotation> annotations, int offset) {
    int size = 3 + offset;
    assertEquals(size, annotations.size());
    Service service = (Service) annotations.get(offset++);
    assertEquals("java.lang.CharSequence", service.interfaceName());
    assertEquals(CharSequence.class, service.interfaceClass());
    com.alibaba.dubbo.config.annotation.Service s = (com.alibaba.dubbo.config.annotation.Service) annotations.get(offset++);
    assertEquals("java.lang.CharSequence", service.interfaceName());
    assertEquals(CharSequence.class, service.interfaceClass());
    Adaptive adaptive = (Adaptive) annotations.get(offset++);
    assertArrayEquals(new String[] { "a", "b", "c" }, adaptive.value());
}
Also used : Adaptive(org.apache.dubbo.common.extension.Adaptive) Service(org.apache.dubbo.config.annotation.Service) DubboService(org.apache.dubbo.config.annotation.DubboService)

Example 2 with Service

use of org.apache.dubbo.config.annotation.Service in project dubbo by alibaba.

the class ServiceBeanNameBuilderTest method testServiceAnnotation.

@Test
public void testServiceAnnotation() {
    Service service = AnnotationUtils.getAnnotation(ServiceBeanNameBuilderTest.class, Service.class);
    ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(service, INTERFACE_CLASS, environment);
    Assertions.assertEquals("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO", builder.build());
    Assertions.assertEquals("ServiceBean:org.apache.dubbo.config.spring.api.DemoService:1.0.0:DUBBO", builder.build());
}
Also used : DemoService(org.apache.dubbo.config.spring.api.DemoService) Service(org.apache.dubbo.config.annotation.Service) Test(org.junit.jupiter.api.Test)

Example 3 with Service

use of org.apache.dubbo.config.annotation.Service in project dubbo by alibaba.

the class MergedAnnotationTest method testMergedService.

@Test
public void testMergedService() {
    Service service1 = AnnotatedElementUtils.getMergedAnnotation(DemoServiceImpl1.class, Service.class);
    Assertions.assertEquals("dubbo", service1.group());
    Assertions.assertEquals("1.0.0", service1.version());
    Service service2 = AnnotatedElementUtils.getMergedAnnotation(DemoServiceImpl2.class, Service.class);
    Assertions.assertEquals("group", service2.group());
    Assertions.assertEquals("2.0", service2.version());
}
Also used : DemoService(org.apache.dubbo.config.spring.api.DemoService) MergedService(org.apache.dubbo.config.spring.annotation.merged.MergedService) Service(org.apache.dubbo.config.annotation.Service) Test(org.junit.jupiter.api.Test)

Example 4 with Service

use of org.apache.dubbo.config.annotation.Service in project dubbo by alibaba.

the class ReferenceAnnotationBeanPostProcessor method doGetInjectedBean.

@Override
protected Object doGetInjectedBean(AnnotationAttributes attributes, Object bean, String beanName, Class<?> injectedType, InjectionMetadata.InjectedElement injectedElement) throws Exception {
    /**
     * The name of bean that annotated Dubbo's {@link Service @Service} in local Spring {@link ApplicationContext}
     */
    String referencedBeanName = buildReferencedBeanName(attributes, injectedType);
    /**
     * The name of bean that is declared by {@link Reference @Reference} annotation injection
     */
    String referenceBeanName = getReferenceBeanName(attributes, injectedType);
    referencedBeanNameIdx.computeIfAbsent(referencedBeanName, k -> new TreeSet<String>()).add(referenceBeanName);
    ReferenceBean referenceBean = buildReferenceBeanIfAbsent(referenceBeanName, attributes, injectedType);
    boolean localServiceBean = isLocalServiceBean(referencedBeanName, referenceBean, attributes);
    prepareReferenceBean(referencedBeanName, referenceBean, localServiceBean);
    registerReferenceBean(referencedBeanName, referenceBean, localServiceBean, referenceBeanName);
    cacheInjectedReferenceBean(referenceBean, injectedElement);
    return getBeanFactory().applyBeanPostProcessorsAfterInitialization(referenceBean.get(), referenceBeanName);
}
Also used : LoggerFactory(org.apache.dubbo.common.logger.LoggerFactory) Arrays(java.util.Arrays) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) HashMap(java.util.HashMap) ReferenceBean(org.apache.dubbo.config.spring.ReferenceBean) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) ConcurrentMap(java.util.concurrent.ConcurrentMap) AbstractAnnotationBeanPostProcessor(com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor) Map(java.util.Map) Service(org.apache.dubbo.config.annotation.Service) AnnotationUtils.getAttribute(com.alibaba.spring.util.AnnotationUtils.getAttribute) Method(java.lang.reflect.Method) Logger(org.apache.dubbo.common.logger.Logger) InjectionMetadata(org.springframework.beans.factory.annotation.InjectionMetadata) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ObjectUtils(org.springframework.util.ObjectUtils) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Reference(org.apache.dubbo.config.annotation.Reference) BeansException(org.springframework.beans.BeansException) ApplicationListener(org.springframework.context.ApplicationListener) Field(java.lang.reflect.Field) ApplicationContext(org.springframework.context.ApplicationContext) Collectors(java.util.stream.Collectors) AnnotationUtils(com.alibaba.spring.util.AnnotationUtils) ApplicationEvent(org.springframework.context.ApplicationEvent) ContextRefreshedEvent(org.springframework.context.event.ContextRefreshedEvent) StringUtils.hasText(org.springframework.util.StringUtils.hasText) ServiceBean(org.apache.dubbo.config.spring.ServiceBean) ServiceBeanNameBuilder.create(org.apache.dubbo.config.spring.beans.factory.annotation.ServiceBeanNameBuilder.create) DubboService(org.apache.dubbo.config.annotation.DubboService) Annotation(java.lang.annotation.Annotation) DubboReference(org.apache.dubbo.config.annotation.DubboReference) AnnotationUtils.getAttributes(com.alibaba.spring.util.AnnotationUtils.getAttributes) AnnotationAttributes(org.springframework.core.annotation.AnnotationAttributes) Collections(java.util.Collections) ApplicationContextAware(org.springframework.context.ApplicationContextAware) TreeSet(java.util.TreeSet) ReferenceBean(org.apache.dubbo.config.spring.ReferenceBean)

Example 5 with Service

use of org.apache.dubbo.config.annotation.Service in project dubbo by alibaba.

the class ServiceBeanTest method testGetService.

@Test
public void testGetService() {
    TestService service = mock(TestService.class);
    ServiceBean serviceBean = new ServiceBean(service);
    Service beanService = serviceBean.getService();
    MatcherAssert.assertThat(beanService, not(nullValue()));
}
Also used : Service(org.apache.dubbo.config.annotation.Service) Test(org.junit.jupiter.api.Test)

Aggregations

Service (org.apache.dubbo.config.annotation.Service)7 Test (org.junit.jupiter.api.Test)5 DubboService (org.apache.dubbo.config.annotation.DubboService)4 Annotation (java.lang.annotation.Annotation)2 Adaptive (org.apache.dubbo.common.extension.Adaptive)2 DemoService (org.apache.dubbo.config.spring.api.DemoService)2 AbstractAnnotationBeanPostProcessor (com.alibaba.spring.beans.factory.annotation.AbstractAnnotationBeanPostProcessor)1 AnnotationUtils (com.alibaba.spring.util.AnnotationUtils)1 AnnotationUtils.getAttribute (com.alibaba.spring.util.AnnotationUtils.getAttribute)1 AnnotationUtils.getAttributes (com.alibaba.spring.util.AnnotationUtils.getAttributes)1 Documented (java.lang.annotation.Documented)1 ElementType (java.lang.annotation.ElementType)1 Inherited (java.lang.annotation.Inherited)1 Retention (java.lang.annotation.Retention)1 RetentionPolicy (java.lang.annotation.RetentionPolicy)1 Target (java.lang.annotation.Target)1 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1