Search in sources :

Example 1 with DubboClassPathBeanDefinitionScanner

use of com.alibaba.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner in project dubbo by alibaba.

the class ServiceAnnotationBeanPostProcessor method registerServiceBeans.

/**
 * Registers Beans whose classes was annotated {@link Service}
 *
 * @param packagesToScan The base packages to scan
 * @param registry       {@link BeanDefinitionRegistry}
 */
private void registerServiceBeans(Set<String> packagesToScan, BeanDefinitionRegistry registry) {
    DubboClassPathBeanDefinitionScanner scanner = new DubboClassPathBeanDefinitionScanner(registry, environment, resourceLoader);
    BeanNameGenerator beanNameGenerator = resolveBeanNameGenerator(registry);
    scanner.setBeanNameGenerator(beanNameGenerator);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Service.class));
    for (String packageToScan : packagesToScan) {
        // Registers @Service Bean first
        scanner.scan(packageToScan);
        // Finds all BeanDefinitionHolders of @Service whether @ComponentScan scans or not.
        Set<BeanDefinitionHolder> beanDefinitionHolders = findServiceBeanDefinitionHolders(scanner, packageToScan, registry, beanNameGenerator);
        if (!CollectionUtils.isEmpty(beanDefinitionHolders)) {
            for (BeanDefinitionHolder beanDefinitionHolder : beanDefinitionHolders) {
                registerServiceBean(beanDefinitionHolder, registry, scanner);
            }
            if (logger.isInfoEnabled()) {
                logger.info(beanDefinitionHolders.size() + " annotated Dubbo's @Service Components { " + beanDefinitionHolders + " } were scanned under package[" + packageToScan + "]");
            }
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("No Spring Bean annotating Dubbo's @Service was found under package[" + packageToScan + "]");
            }
        }
    }
}
Also used : AnnotationBeanNameGenerator(org.springframework.context.annotation.AnnotationBeanNameGenerator) BeanNameGenerator(org.springframework.beans.factory.support.BeanNameGenerator) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) Service(com.alibaba.dubbo.config.annotation.Service) DubboClassPathBeanDefinitionScanner(com.alibaba.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner)

Aggregations

Service (com.alibaba.dubbo.config.annotation.Service)1 DubboClassPathBeanDefinitionScanner (com.alibaba.dubbo.config.spring.context.annotation.DubboClassPathBeanDefinitionScanner)1 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)1 BeanNameGenerator (org.springframework.beans.factory.support.BeanNameGenerator)1 AnnotationBeanNameGenerator (org.springframework.context.annotation.AnnotationBeanNameGenerator)1 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)1