Search in sources :

Example 36 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.

the class ConfigurationClassParser method parse.

public void parse(Set<BeanDefinitionHolder> configCandidates) {
    this.deferredImportSelectors = new LinkedList<>();
    for (BeanDefinitionHolder holder : configCandidates) {
        BeanDefinition bd = holder.getBeanDefinition();
        try {
            if (bd instanceof AnnotatedBeanDefinition) {
                parse(((AnnotatedBeanDefinition) bd).getMetadata(), holder.getBeanName());
            } else if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
                parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
            } else {
                parse(bd.getBeanClassName(), holder.getBeanName());
            }
        } catch (BeanDefinitionStoreException ex) {
            throw ex;
        } catch (Throwable ex) {
            throw new BeanDefinitionStoreException("Failed to parse configuration class [" + bd.getBeanClassName() + "]", ex);
        }
    }
    processDeferredImportSelectors();
}
Also used : AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 37 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProvider method addCandidateComponentsFromIndex.

private Set<BeanDefinition> addCandidateComponentsFromIndex(String basePackage) {
    Set<BeanDefinition> candidates = new LinkedHashSet<>();
    try {
        Set<String> types = new HashSet<>();
        for (TypeFilter filter : this.includeFilters) {
            String stereotype = extractStereotype(filter);
            if (stereotype == null) {
                throw new IllegalArgumentException("Failed to extract stereotype from " + filter);
            }
            types.addAll(this.componentsIndex.getCandidateTypes(basePackage, stereotype));
        }
        boolean traceEnabled = logger.isTraceEnabled();
        boolean debugEnabled = logger.isDebugEnabled();
        for (String type : types) {
            MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(type);
            if (isCandidateComponent(metadataReader)) {
                AnnotatedGenericBeanDefinition sbd = new AnnotatedGenericBeanDefinition(metadataReader.getAnnotationMetadata());
                if (isCandidateComponent(sbd)) {
                    if (debugEnabled) {
                        logger.debug("Using candidate component class from index: " + type);
                    }
                    candidates.add(sbd);
                } else {
                    if (debugEnabled) {
                        logger.debug("Ignored because not a concrete top-level class: " + type);
                    }
                }
            } else {
                if (traceEnabled) {
                    logger.trace("Ignored because matching an exclude filter: " + type);
                }
            }
        }
    } catch (IOException ex) {
        throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
    }
    return candidates;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) MetadataReader(org.springframework.core.type.classreading.MetadataReader) TypeFilter(org.springframework.core.type.filter.TypeFilter) AnnotationTypeFilter(org.springframework.core.type.filter.AnnotationTypeFilter) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter) IOException(java.io.IOException) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 38 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project spring-framework by spring-projects.

the class ClassPathScanningCandidateComponentProvider method scanCandidateComponents.

private Set<BeanDefinition> scanCandidateComponents(String basePackage) {
    Set<BeanDefinition> candidates = new LinkedHashSet<>();
    try {
        String packageSearchPath = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + resolveBasePackage(basePackage) + '/' + this.resourcePattern;
        Resource[] resources = this.resourcePatternResolver.getResources(packageSearchPath);
        boolean traceEnabled = logger.isTraceEnabled();
        boolean debugEnabled = logger.isDebugEnabled();
        for (Resource resource : resources) {
            if (traceEnabled) {
                logger.trace("Scanning " + resource);
            }
            if (resource.isReadable()) {
                try {
                    MetadataReader metadataReader = this.metadataReaderFactory.getMetadataReader(resource);
                    if (isCandidateComponent(metadataReader)) {
                        ScannedGenericBeanDefinition sbd = new ScannedGenericBeanDefinition(metadataReader);
                        sbd.setResource(resource);
                        sbd.setSource(resource);
                        if (isCandidateComponent(sbd)) {
                            if (debugEnabled) {
                                logger.debug("Identified candidate component class: " + resource);
                            }
                            candidates.add(sbd);
                        } else {
                            if (debugEnabled) {
                                logger.debug("Ignored because not a concrete top-level class: " + resource);
                            }
                        }
                    } else {
                        if (traceEnabled) {
                            logger.trace("Ignored because not matching any filter: " + resource);
                        }
                    }
                } catch (Throwable ex) {
                    throw new BeanDefinitionStoreException("Failed to read candidate component class: " + resource, ex);
                }
            } else {
                if (traceEnabled) {
                    logger.trace("Ignored because not readable: " + resource);
                }
            }
        }
    } catch (IOException ex) {
        throw new BeanDefinitionStoreException("I/O failure during classpath scanning", ex);
    }
    return candidates;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) Resource(org.springframework.core.io.Resource) MetadataReader(org.springframework.core.type.classreading.MetadataReader) IOException(java.io.IOException) AnnotatedBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AnnotatedGenericBeanDefinition(org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)

Example 39 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project aries by apache.

the class BlueprintBeanFactory method registerBeanDefinition.

@Override
public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException {
    ComponentDefinitionRegistry registry = container.getComponentDefinitionRegistry();
    ComponentMetadata metadata = registry.getComponentDefinition(beanName);
    if (metadata != null && !(metadata instanceof SpringMetadata)) {
        throw new BeanDefinitionStoreException(beanDefinition.getResourceDescription(), beanName, "Cannot register bean definition [" + beanDefinition + "] for bean '" + beanName + "': There is already bound.");
    }
    super.registerBeanDefinition(beanName, beanDefinition);
    if (!beanDefinition.isAbstract()) {
        registry.registerComponentDefinition(new SpringMetadata(beanName));
    }
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata)

Aggregations

BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)39 Test (org.junit.Test)14 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)11 IOException (java.io.IOException)8 LinkedHashSet (java.util.LinkedHashSet)6 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)5 MockServletContext (org.springframework.mock.web.test.MockServletContext)5 ArrayList (java.util.ArrayList)4 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)4 Map (java.util.Map)3 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)3 BeanCreationException (org.springframework.beans.factory.BeanCreationException)3 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)3 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)3 Resource (org.springframework.core.io.Resource)3 Method (java.lang.reflect.Method)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2