com.alibaba.dubbo.config.annotation.Service Java Examples

The following examples show how to use com.alibaba.dubbo.config.annotation.Service. 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: AnnotationBean.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example #2
Source File: AnnotationBean.java    From dubbox-hystrix with Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example #3
Source File: AnnotationBean.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
    throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[]{BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[]{(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[]{packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example #4
Source File: AnnotationBean.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example #5
Source File: AnnotationBean.java    From spring-boot-starter-dubbo with Apache License 2.0 6 votes vote down vote up
private Class<?> resolveServiceInterfaceClass(Class<?> annotatedServiceBeanClass, Service service) {
	Class<?> interfaceClass = service.interfaceClass();
	if (void.class.equals(interfaceClass)) {
		interfaceClass = null;
		String interfaceClassName = service.interfaceName();
		if (StringUtils.hasText(interfaceClassName)) {
			if (ClassUtils.isPresent(interfaceClassName, classLoader)) {
				interfaceClass = resolveClassName(interfaceClassName, classLoader);
			}
		}
	}
	if(interfaceClass==null){
		return null;
	}
	Assert.isTrue(interfaceClass.isInterface(), "The type that was annotated @Service is not an interface!");
	return interfaceClass;
}
 
Example #6
Source File: AnnotationBean.java    From dubbox with Apache License 2.0 6 votes vote down vote up
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
        throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] {BeanDefinitionRegistry.class, boolean.class}).newInstance(new Object[] {(BeanDefinitionRegistry) beanFactory, true});
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[]{String[].class});
            scan.invoke(scanner, new Object[] {packages});
        } catch (Throwable e) {
            // spring 2.0
        }
    }
}
 
Example #7
Source File: AnnotationUtils.java    From dubbo-2.6.5 with Apache License 2.0 6 votes vote down vote up
public static String resolveInterfaceName(Service service, Class<?> defaultInterfaceClass)
        throws IllegalStateException {

    String interfaceName;
    if (StringUtils.hasText(service.interfaceName())) {
        interfaceName = service.interfaceName();
    } else if (!void.class.equals(service.interfaceClass())) {
        interfaceName = service.interfaceClass().getName();
    } else if (defaultInterfaceClass.isInterface()) {
        interfaceName = defaultInterfaceClass.getName();
    } else {
        throw new IllegalStateException(
                "The @Service undefined interfaceClass or interfaceName, and the type "
                        + defaultInterfaceClass.getName() + " is not a interface.");
    }

    return interfaceName;

}
 
Example #8
Source File: DubboServiceModule.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
protected void bindDubboService() {
    final List<ServiceConfig<Object>> serviceConfigs = Lists.newArrayList();
    final Injector injector = Globals.get(Injector.class);
    ClassScanner.filter(Service.class).forEach(cls -> {
        if (cls.isInterface()) {
            LOGGER.warn("Ignore interface API of {}", cls.getName());
            return;
        }

        final Class<?>[] itfs = cls.getInterfaces();
        if (ArrayUtils.isEmpty(itfs)) {
            LOGGER.warn("Ignore no interface implement API of {}", cls.getName());
            return;
        }

        final Service service = cls.getAnnotation(Service.class);
        final Object instance = injector.getInstance(cls);
        for (Class<?> itf : itfs) {
            final ServiceConfig<Object> serviceConfig = new ServiceConfig<>(service);
            serviceConfig.setInterface(itf);
            serviceConfig.setRef(instance);
            serviceConfigs.add(serviceConfig);
        }
    });

    serviceConfigs.forEach(conf -> conf.export());
}
 
Example #9
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * Registers {@link ServiceBean} from new annotated {@link Service} {@link BeanDefinition}
 *
 * @param beanDefinitionHolder
 * @param registry
 * @param scanner
 * @see ServiceBean
 * @see BeanDefinition
 */
private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, BeanDefinitionRegistry registry,
                                 DubboClassPathBeanDefinitionScanner scanner) {

    Class<?> beanClass = resolveClass(beanDefinitionHolder);

    Service service = findAnnotation(beanClass, Service.class);
    if(null == service){
        service = this.defaultService;
    }

    Class<?> interfaceClass = resolveServiceInterfaceClass(beanClass, service);

    String annotatedServiceBeanName = beanDefinitionHolder.getBeanName();

    AbstractBeanDefinition serviceBeanDefinition =
            buildServiceBeanDefinition(service, interfaceClass, annotatedServiceBeanName);

    // ServiceBean Bean name
    String beanName = generateServiceBeanName(service, interfaceClass, annotatedServiceBeanName);

    if (scanner.checkCandidate(beanName, serviceBeanDefinition)) { // check duplicated candidate bean
        registry.registerBeanDefinition(beanName, serviceBeanDefinition);

        if (logger.isInfoEnabled()) {
            logger.warn("The BeanDefinition[" + serviceBeanDefinition +
                    "] of ServiceBean has been registered with name : " + beanName);
        }

    } else {

        if (logger.isWarnEnabled()) {
            logger.warn("The Duplicated BeanDefinition[" + serviceBeanDefinition +
                    "] of ServiceBean[ bean name : " + beanName +
                    "] was be found , Did @DubboComponentScan scan to same package in many times?");
        }

    }

}
 
Example #10
Source File: AnnotationBean.java    From spring-boot-starter-dubbo with Apache License 2.0 5 votes vote down vote up
protected void postProcessAnnotationPackageService() {
	if (this.annotationPackages.length == 0) {
		return;
	}
	DubboClassPathBeanDefinitionScanner definitionScanner = new DubboClassPathBeanDefinitionScanner( registry, environment, resourceLoader);
	definitionScanner.addIncludeFilter(new AnnotationTypeFilter(Service.class));
	Set<BeanDefinitionHolder> definitionHolders = definitionScanner.doScan(this.annotationPackages);
	for (BeanDefinitionHolder definitionHolder : definitionHolders) {
		registerServiceBean(definitionHolder, registry);
	}
	logger.debug("{} annotated @Service Components { {} } were scanned under package[{}]", definitionHolders.size(), definitionHolders, this.annotationPackages);
}
 
Example #11
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-alibaba-dubbo with Apache License 2.0 5 votes vote down vote up
/**
 * Registers {@link ServiceBean} from new annotated {@link Service} {@link BeanDefinition}
 *
 * @param beanDefinitionHolder
 * @param registry
 * @param scanner
 * @see ServiceBean
 * @see BeanDefinition
 */
private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, BeanDefinitionRegistry registry,
                                 DubboClassPathBeanDefinitionScanner scanner) {

    Class<?> beanClass = resolveClass(beanDefinitionHolder);

    Service service = findAnnotation(beanClass, Service.class);
    if (null == service) {
        service = this.defaultService;
    }

    Class<?> interfaceClass = resolveServiceInterfaceClass(beanClass, service);

    String annotatedServiceBeanName = beanDefinitionHolder.getBeanName();

    AbstractBeanDefinition serviceBeanDefinition =
            buildServiceBeanDefinition(service, interfaceClass, annotatedServiceBeanName);

    // ServiceBean Bean name
    String beanName = generateServiceBeanName(service, interfaceClass, annotatedServiceBeanName);

    if (scanner.checkCandidate(beanName, serviceBeanDefinition)) { // check duplicated candidate bean
        registry.registerBeanDefinition(beanName, serviceBeanDefinition);

        if (logger.isInfoEnabled()) {
            logger.warn("The BeanDefinition[" + serviceBeanDefinition +
                    "] of ServiceBean has been registered with name : " + beanName);
        }

    } else {

        if (logger.isWarnEnabled()) {
            logger.warn("The Duplicated BeanDefinition[" + serviceBeanDefinition +
                    "] of ServiceBean[ bean name : " + beanName +
                    "] was be found , Did @DubboComponentScan scan to same package in many times?");
        }

    }

}
 
Example #12
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-alibaba-dubbo with Apache License 2.0 5 votes vote down vote up
public FeignClientToDubboProviderBeanPostProcessor(Set<String> packagesToScan) {
    this.packagesToScan = packagesToScan;
    @Service
    final class DefaultServiceClass {
    }
    ;
    this.defaultService = DefaultServiceClass.class.getAnnotation(Service.class);
}
 
Example #13
Source File: DubboProviderAutoConfiguration.java    From dubbo-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void init() throws Exception {
  Map<String, Object> beanMap = this.applicationContext.getBeansWithAnnotation(Service.class);
  if (beanMap != null && beanMap.size() > 0) {
    this.initIdConfigMap(this.properties);
    for (Map.Entry<String, Object> entry : beanMap.entrySet()) {
      this.initProviderBean(entry.getKey(), entry.getValue());
    }
  }
}
 
Example #14
Source File: ServiceBeanTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetService() {
    TestService service = mock(TestService.class);
    ServiceBean serviceBean = new ServiceBean(service);

    Service beanService = serviceBean.getService();
    Assert.assertThat(beanService, not(nullValue()));
}
 
Example #15
Source File: ServiceBeanNameBuilderTest.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
@Test
public void testServiceAnnotation() {
    Service service = AnnotationUtils.getAnnotation(ServiceBeanNameBuilderTest.class, Service.class);
    ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(service, INTERFACE_CLASS, environment);
    Assert.assertEquals(BEAN_NAME,
            builder.build());
}
 
Example #16
Source File: DubboProviderAutoConfiguration.java    From dubbo-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
private void initProviderBean(String beanName, Object bean) throws Exception {
  Service service = this.applicationContext.findAnnotationOnBean(beanName, Service.class);
  ServiceBean<Object> serviceConfig = new ServiceBean<Object>(service);
  if ((service.interfaceClass() == null || service.interfaceClass() == void.class)
      && (service.interfaceName() == null || "".equals(service.interfaceName()))) {
    Class<?>[] interfaces = bean.getClass().getInterfaces();
    if (interfaces.length > 0) {
      serviceConfig.setInterface(interfaces[0]);
    }
  }

  Environment environment = this.applicationContext.getEnvironment();
  String application = service.application();
  serviceConfig.setApplication(this.parseApplication(application, this.properties, environment,
      beanName, "application", application));
  String module = service.module();
  serviceConfig.setModule(
      this.parseModule(module, this.properties, environment, beanName, "module", module));
  String[] registries = service.registry();
  serviceConfig.setRegistries(
      this.parseRegistries(registries, this.properties, environment, beanName, "registry"));
  String[] protocols = service.protocol();
  serviceConfig.setProtocols(
      this.parseProtocols(protocols, this.properties, environment, beanName, "registry"));
  String monitor = service.monitor();
  serviceConfig.setMonitor(
      this.parseMonitor(monitor, this.properties, environment, beanName, "monitor", monitor));
  String provider = service.provider();
  serviceConfig.setProvider(
      this.parseProvider(provider, this.properties, environment, beanName, "provider", provider));

  serviceConfig.setApplicationContext(this.applicationContext);
  serviceConfig.afterPropertiesSet();
  serviceConfig.setRef(bean);
  serviceConfig.export();
}
 
Example #17
Source File: ServiceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
/**
     * Registers {@link ServiceBean} from new annotated {@link Service} {@link BeanDefinition} 从新的带注释的服务bean定义注册ServiceBean
     *
     * @param beanDefinitionHolder
     * @param registry
     * @param scanner
     * @see ServiceBean
     * @see BeanDefinition
     */
    private void registerServiceBean(BeanDefinitionHolder beanDefinitionHolder, BeanDefinitionRegistry registry,
                                     DubboClassPathBeanDefinitionScanner scanner) {

        Class<?> beanClass = resolveClass(beanDefinitionHolder);

//        从beanClass上获取@service注解对象
        Service service = findAnnotation(beanClass, Service.class);

//        解析@service注解指定的interface的Class对象
        Class<?> interfaceClass = resolveServiceInterfaceClass(beanClass, service);

        String annotatedServiceBeanName = beanDefinitionHolder.getBeanName();

//        构建service bean定义=》
        AbstractBeanDefinition serviceBeanDefinition =
                buildServiceBeanDefinition(service, interfaceClass, annotatedServiceBeanName);

        // ServiceBean Bean name 默认是接口类的权限定名
        String beanName = generateServiceBeanName(service, interfaceClass, annotatedServiceBeanName);

        if (scanner.checkCandidate(beanName, serviceBeanDefinition)) { // check duplicated candidate bean
            registry.registerBeanDefinition(beanName, serviceBeanDefinition);

            if (logger.isInfoEnabled()) {
                logger.warn("The BeanDefinition[" + serviceBeanDefinition +
                        "] of ServiceBean has been registered with name : " + beanName);
            }

        } else {

            if (logger.isWarnEnabled()) {
                logger.warn("The Duplicated BeanDefinition[" + serviceBeanDefinition +
                        "] of ServiceBean[ bean name : " + beanName +
                        "] was be found , Did @DubboComponentScan scan to same package in many times?");
            }

        }

    }
 
Example #18
Source File: ServiceBean.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceBean(Service service) {
    super(service);
}
 
Example #19
Source File: AnnotationBean.java    From spring-boot-starter-dubbo with Apache License 2.0 4 votes vote down vote up
private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class<?> interfaceClass,
		String annotatedServiceBeanName) {
	BeanDefinitionBuilder builder = 
			rootBeanDefinition(ServiceBean.class)
			.addConstructorArgValue(service)
			.addPropertyReference("ref", annotatedServiceBeanName)
			.addPropertyValue("interfaceClass", interfaceClass);
	/**
	 * Add {@link com.alibaba.dubbo.config.ProviderConfig} Bean reference
	 */
	String providerConfigBeanName = service.provider();
	if (StringUtils.hasText(providerConfigBeanName)) {
		builder.addPropertyReference("provider", providerConfigBeanName);
	}
	/**
	 * Add {@link com.alibaba.dubbo.config.MonitorConfig} Bean reference
	 */
	String monitorConfigBeanName = service.monitor();
	if (StringUtils.hasText(monitorConfigBeanName)) {
		builder.addPropertyReference("monitor", monitorConfigBeanName);
	}
	/**
	 * Add {@link com.alibaba.dubbo.config.ApplicationConfig} Bean reference
	 */
	String applicationConfigBeanName = service.application();
	if (StringUtils.hasText(applicationConfigBeanName)) {
		builder.addPropertyReference("application", applicationConfigBeanName);
	}
	/**
	 * Add {@link com.alibaba.dubbo.config.ModuleConfig} Bean reference
	 */
	String moduleConfigBeanName = service.module();
	if (StringUtils.hasText(moduleConfigBeanName)) {
		builder.addPropertyReference("application", moduleConfigBeanName);
	}
	/**
	 * Add {@link com.alibaba.dubbo.config.RegistryConfig} Bean reference
	 */
	String[] registryConfigBeanNames = service.registry();
	List<RuntimeBeanReference> registryRuntimeBeanReferences = toRuntimeBeanReferences(registryConfigBeanNames);
	if (!registryRuntimeBeanReferences.isEmpty()) {
		builder.addPropertyValue("registries", registryRuntimeBeanReferences);
	}
	/**
	 * Add {@link com.alibaba.dubbo.config.ProtocolConfig} Bean reference
	 */
	String[] protocolConfigBeanNames = service.protocol();
	List<RuntimeBeanReference> protocolRuntimeBeanReferences = toRuntimeBeanReferences(protocolConfigBeanNames);
	if (!registryRuntimeBeanReferences.isEmpty()) {
		builder.addPropertyValue("protocols", protocolRuntimeBeanReferences);
	}
	return builder.getBeanDefinition();

}
 
Example #20
Source File: ServiceConfig.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public ServiceConfig(Service service) {
    appendAnnotation(Service.class, service);
}
 
Example #21
Source File: ServiceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceConfig(Service service) {
    appendAnnotation(Service.class, service);
}
 
Example #22
Source File: ServiceBean.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceBean(Service service) {
    super(service);
}
 
Example #23
Source File: ServiceBean.java    From dubbox-hystrix with Apache License 2.0 4 votes vote down vote up
public ServiceBean(Service service) {
    super(service);
}
 
Example #24
Source File: ServiceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceConfig(Service service) {
    appendAnnotation(Service.class, service);
}
 
Example #25
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-dubbo with Apache License 2.0 4 votes vote down vote up
/**
 * Generates the bean name of {@link ServiceBean}
 *
 * @param service
 * @param interfaceClass           the class of interface annotated {@link Service}
 * @param annotatedServiceBeanName the bean name of annotated {@link Service}
 * @return ServiceBean@interfaceClassName#annotatedServiceBeanName
 * @since 2.5.9
 */
private String generateServiceBeanName(Service service, Class<?> interfaceClass, String annotatedServiceBeanName) {

    StringBuilder beanNameBuilder = new StringBuilder(ServiceBean.class.getSimpleName());

    beanNameBuilder.append(SEPARATOR).append(annotatedServiceBeanName);

    String interfaceClassName = interfaceClass.getName();

    beanNameBuilder.append(SEPARATOR).append(interfaceClassName);

    String version = service.version();

    if (StringUtils.hasText(version)) {
        beanNameBuilder.append(SEPARATOR).append(version);
    }

    String group = service.group();

    if (StringUtils.hasText(group)) {
        beanNameBuilder.append(SEPARATOR).append(group);
    }

    return beanNameBuilder.toString();

}
 
Example #26
Source File: ServiceConfig.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceConfig(Service service) {
    appendAnnotation(Service.class, service);
}
 
Example #27
Source File: ServiceBean.java    From dubbox with Apache License 2.0 4 votes vote down vote up
public ServiceBean(Service service) {
    super(service);
}
 
Example #28
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-dubbo with Apache License 2.0 4 votes vote down vote up
private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class<?> interfaceClass,
                                                          String annotatedServiceBeanName) {

    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceBean.class);

    AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

    String[] ignoreAttributeNames = of("provider", "monitor", "application", "module", "registry", "protocol", "interface");

    propertyValues.addPropertyValues(new AnnotationPropertyValuesAdapter(service, environment, ignoreAttributeNames));

    // References "ref" property to annotated-@Service Bean
    addPropertyReference(builder, "ref", annotatedServiceBeanName);
    // Set interface
    builder.addPropertyValue("interface", interfaceClass.getName());

    /**
     * Add {@link com.alibaba.dubbo.config.ProviderConfig} Bean reference
     */
    String providerConfigBeanName = service.provider();
    if (StringUtils.hasText(providerConfigBeanName)) {
        addPropertyReference(builder, "provider", providerConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.MonitorConfig} Bean reference
     */
    String monitorConfigBeanName = service.monitor();
    if (StringUtils.hasText(monitorConfigBeanName)) {
        addPropertyReference(builder, "monitor", monitorConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ApplicationConfig} Bean reference
     */
    String applicationConfigBeanName = service.application();
    if (StringUtils.hasText(applicationConfigBeanName)) {
        addPropertyReference(builder, "application", applicationConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ModuleConfig} Bean reference
     */
    String moduleConfigBeanName = service.module();
    if (StringUtils.hasText(moduleConfigBeanName)) {
        addPropertyReference(builder, "module", moduleConfigBeanName);
    }


    /**
     * Add {@link com.alibaba.dubbo.config.RegistryConfig} Bean reference
     */
    String[] registryConfigBeanNames = service.registry();

    List<RuntimeBeanReference> registryRuntimeBeanReferences = toRuntimeBeanReferences(registryConfigBeanNames);

    if (!registryRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("registries", registryRuntimeBeanReferences);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ProtocolConfig} Bean reference
     */
    String[] protocolConfigBeanNames = service.protocol();

    List<RuntimeBeanReference> protocolRuntimeBeanReferences = toRuntimeBeanReferences(protocolConfigBeanNames);

    if (!protocolRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("protocols", protocolRuntimeBeanReferences);
    }

    return builder.getBeanDefinition();

}
 
Example #29
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-dubbo with Apache License 2.0 4 votes vote down vote up
public FeignClientToDubboProviderBeanPostProcessor(Set<String> packagesToScan) {
    this.packagesToScan = packagesToScan;
    // 产生@Service 默认配置实例
    @Service final class DefaultServiceClass{};
    this.defaultService = DefaultServiceClass.class.getAnnotation(Service.class);
}
 
Example #30
Source File: FeignClientToDubboProviderBeanPostProcessor.java    From spring-cloud-alibaba-dubbo with Apache License 2.0 4 votes vote down vote up
private AbstractBeanDefinition buildServiceBeanDefinition(Service service, Class<?> interfaceClass,
                                                          String annotatedServiceBeanName) {

    BeanDefinitionBuilder builder = rootBeanDefinition(ServiceBean.class);

    AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();

    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();

    String[] ignoreAttributeNames = of("provider", "monitor", "application", "module", "registry", "protocol", "interface");

    propertyValues.addPropertyValues(new AnnotationPropertyValuesAdapter(service, environment, ignoreAttributeNames));

    // References "ref" property to annotated-@Service Bean
    addPropertyReference(builder, "ref", annotatedServiceBeanName);
    // Set interface
    builder.addPropertyValue("interface", interfaceClass.getName());

    /**
     * Add {@link com.alibaba.dubbo.config.ProviderConfig} Bean reference
     */
    String providerConfigBeanName = service.provider();
    if (StringUtils.hasText(providerConfigBeanName)) {
        addPropertyReference(builder, "provider", providerConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.MonitorConfig} Bean reference
     */
    String monitorConfigBeanName = service.monitor();
    if (StringUtils.hasText(monitorConfigBeanName)) {
        addPropertyReference(builder, "monitor", monitorConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ApplicationConfig} Bean reference
     */
    String applicationConfigBeanName = service.application();
    if (StringUtils.hasText(applicationConfigBeanName)) {
        addPropertyReference(builder, "application", applicationConfigBeanName);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ModuleConfig} Bean reference
     */
    String moduleConfigBeanName = service.module();
    if (StringUtils.hasText(moduleConfigBeanName)) {
        addPropertyReference(builder, "module", moduleConfigBeanName);
    }


    /**
     * Add {@link com.alibaba.dubbo.config.RegistryConfig} Bean reference
     */
    String[] registryConfigBeanNames = service.registry();

    List<RuntimeBeanReference> registryRuntimeBeanReferences = toRuntimeBeanReferences(registryConfigBeanNames);

    if (!registryRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("registries", registryRuntimeBeanReferences);
    }

    /**
     * Add {@link com.alibaba.dubbo.config.ProtocolConfig} Bean reference
     */
    String[] protocolConfigBeanNames = service.protocol();

    List<RuntimeBeanReference> protocolRuntimeBeanReferences = toRuntimeBeanReferences(protocolConfigBeanNames);

    if (!protocolRuntimeBeanReferences.isEmpty()) {
        builder.addPropertyValue("protocols", protocolRuntimeBeanReferences);
    }

    return builder.getBeanDefinition();

}