Search in sources :

Example 21 with ScopeMetadata

use of cn.taketoday.context.loader.ScopeMetadata in project today-framework by TAKETODAY.

the class ClassPathBeanDefinitionScanner method scanning.

/**
 * Perform a scan within the specified base packages,
 * returning the registered bean definitions.
 * <p>This method does <i>not</i> register an annotation config processor
 * but rather leaves this up to the caller.
 *
 * @param basePackages the packages to check for annotated classes
 * @return set of beans registered if any for tooling registration purposes (never {@code null})
 */
@Deprecated
public Set<BeanDefinition> scanning(String... basePackages) {
    Assert.notEmpty(basePackages, "At least one base package must be specified");
    LinkedHashSet<BeanDefinition> beanDefinitions = new LinkedHashSet<>();
    for (String basePackage : basePackages) {
        try {
            scanCandidateComponents(basePackage, (metadataReader, metadataReaderFactory) -> {
                ScannedGenericBeanDefinition candidate = new ScannedGenericBeanDefinition(metadataReader);
                candidate.setSource(metadataReader.getResource());
                ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(candidate);
                candidate.setScope(scopeMetadata.getScopeName());
                AnnotationConfigUtils.processCommonDefinitionAnnotations(candidate);
                String beanName = beanNamePopulator.populateName(candidate, registry);
                postProcessBeanDefinition(candidate, beanName);
                if (checkCandidate(beanName, candidate)) {
                    beanDefinitions.add(candidate);
                    registerBeanDefinition(candidate, registry);
                }
            });
        } catch (IOException ex) {
            throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
        }
    }
    return beanDefinitions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ScopeMetadata(cn.taketoday.context.loader.ScopeMetadata) BeanDefinitionStoreException(cn.taketoday.beans.factory.BeanDefinitionStoreException) IOException(java.io.IOException) BeanDefinition(cn.taketoday.beans.factory.config.BeanDefinition) AbstractBeanDefinition(cn.taketoday.beans.factory.support.AbstractBeanDefinition)

Example 22 with ScopeMetadata

use of cn.taketoday.context.loader.ScopeMetadata in project today-framework by TAKETODAY.

the class ClassPathBeanDefinitionScanner method scan.

/**
 * Perform a scan within the specified base packages and consume the registered
 * bean definitions.
 * <p>This method does <i>not</i> register an annotation config processor
 * but rather leaves this up to the caller.
 *
 * @param consumer set of beans registered if any for tooling registration purposes
 * @param basePackages the packages to check for annotated classes
 */
public void scan(@Nullable Consumer<BeanDefinitionHolder> consumer, String... basePackages) {
    for (String basePackage : basePackages) {
        try {
            scanCandidateComponents(basePackage, (metadataReader, factory) -> {
                ScannedGenericBeanDefinition candidate = new ScannedGenericBeanDefinition(metadataReader);
                candidate.setResource(metadataReader.getResource());
                ScopeMetadata scopeMetadata = scopeMetadataResolver.resolveScopeMetadata(candidate);
                candidate.setScope(scopeMetadata.getScopeName());
                String beanName = beanNamePopulator.populateName(candidate, registry);
                postProcessBeanDefinition(candidate, beanName);
                AnnotationConfigUtils.processCommonDefinitionAnnotations(candidate);
                if (checkCandidate(beanName, candidate)) {
                    BeanDefinitionHolder holder = new BeanDefinitionHolder(candidate, beanName);
                    holder = AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, holder, registry);
                    if (consumer != null) {
                        consumer.accept(holder);
                    }
                    registerBeanDefinition(holder, registry);
                }
            });
        } catch (IOException ex) {
            throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
        }
    }
}
Also used : ScopeMetadata(cn.taketoday.context.loader.ScopeMetadata) BeanDefinitionStoreException(cn.taketoday.beans.factory.BeanDefinitionStoreException) BeanDefinitionHolder(cn.taketoday.beans.factory.config.BeanDefinitionHolder) IOException(java.io.IOException)

Aggregations

ScopeMetadata (cn.taketoday.context.loader.ScopeMetadata)22 AnnotatedGenericBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedGenericBeanDefinition)16 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)14 Test (org.junit.jupiter.api.Test)14 BeanDefinitionHolder (cn.taketoday.beans.factory.config.BeanDefinitionHolder)5 BeanDefinitionStoreException (cn.taketoday.beans.factory.BeanDefinitionStoreException)4 MetadataReader (cn.taketoday.core.type.classreading.MetadataReader)4 MetadataReaderFactory (cn.taketoday.core.type.classreading.MetadataReaderFactory)4 SimpleMetadataReaderFactory (cn.taketoday.core.type.classreading.SimpleMetadataReaderFactory)4 IOException (java.io.IOException)4 AutowireCandidateQualifier (cn.taketoday.beans.factory.support.AutowireCandidateQualifier)2 Resource (cn.taketoday.core.io.Resource)2 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)1 AbstractBeanDefinition (cn.taketoday.beans.factory.support.AbstractBeanDefinition)1 LinkedHashSet (java.util.LinkedHashSet)1