Search in sources :

Example 21 with BeanDefinitionStoreException

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

the class AbstractUserDetailsServiceBeanDefinitionParser method resolveId.

private String resolveId(Element element, AbstractBeanDefinition definition, ParserContext pc) throws BeanDefinitionStoreException {
    String id = element.getAttribute("id");
    if (pc.isNested()) {
        // We're inside an <authentication-provider> element
        if (!StringUtils.hasText(id)) {
            id = pc.getReaderContext().generateBeanName(definition);
        }
        BeanDefinition container = pc.getContainingBeanDefinition();
        container.getPropertyValues().add("userDetailsService", new RuntimeBeanReference(id));
    }
    if (StringUtils.hasText(id)) {
        return id;
    }
    // If top level, use the default name or throw an exception if already used
    if (pc.getRegistry().containsBeanDefinition(BeanIds.USER_DETAILS_SERVICE)) {
        throw new BeanDefinitionStoreException("No id supplied and another " + "bean is already registered as " + BeanIds.USER_DETAILS_SERVICE);
    }
    return BeanIds.USER_DETAILS_SERVICE;
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 22 with BeanDefinitionStoreException

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

the class AopNamespaceHandlerPointcutErrorTests method testDuplicatePointcutConfig.

@Test
public void testDuplicatePointcutConfig() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(qualifiedResource(getClass(), "pointcutDuplication.xml"));
        fail("parsing should have caused a BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        assertTrue(ex.contains(BeanDefinitionParsingException.class));
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 23 with BeanDefinitionStoreException

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

the class AopNamespaceHandlerPointcutErrorTests method testMissingPointcutConfig.

@Test
public void testMissingPointcutConfig() {
    try {
        DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
        new XmlBeanDefinitionReader(bf).loadBeanDefinitions(qualifiedResource(getClass(), "pointcutMissing.xml"));
        fail("parsing should have caused a BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
        assertTrue(ex.contains(BeanDefinitionParsingException.class));
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 24 with BeanDefinitionStoreException

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

the class BeanTypeRegistry method addBeanTypeForNonAliasDefinition.

private void addBeanTypeForNonAliasDefinition(String name) {
    try {
        String factoryName = BeanFactory.FACTORY_BEAN_PREFIX + name;
        RootBeanDefinition beanDefinition = (RootBeanDefinition) this.beanFactory.getMergedBeanDefinition(name);
        if (!beanDefinition.isAbstract() && !requiresEagerInit(beanDefinition.getFactoryBeanName())) {
            if (this.beanFactory.isFactoryBean(factoryName)) {
                Class<?> factoryBeanGeneric = getFactoryBeanGeneric(this.beanFactory, beanDefinition, name);
                this.beanTypes.put(name, factoryBeanGeneric);
                this.beanTypes.put(factoryName, this.beanFactory.getType(factoryName));
            } else {
                this.beanTypes.put(name, this.beanFactory.getType(name));
            }
        }
    } catch (CannotLoadBeanClassException ex) {
        // Probably contains a placeholder
        logIgnoredError("bean class loading failure for bean", name, ex);
    } catch (BeanDefinitionStoreException ex) {
        // Probably contains a placeholder
        logIgnoredError("unresolvable metadata in bean definition", name, ex);
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) CannotLoadBeanClassException(org.springframework.beans.factory.CannotLoadBeanClassException) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition)

Example 25 with BeanDefinitionStoreException

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

the class PropertyResourceConfigurerTests method testPropertyPlaceholderConfigurerWithCircularReference.

@Test
public void testPropertyPlaceholderConfigurerWithCircularReference() {
    factory.registerBeanDefinition("tb", genericBeanDefinition(TestBean.class).addPropertyValue("age", "${age}").addPropertyValue("name", "name${var}").getBeanDefinition());
    PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
    Properties props = new Properties();
    props.setProperty("age", "99");
    props.setProperty("var", "${m}");
    props.setProperty("m", "${var}");
    ppc.setProperties(props);
    try {
        ppc.postProcessBeanFactory(factory);
        fail("Should have thrown BeanDefinitionStoreException");
    } catch (BeanDefinitionStoreException ex) {
    // expected
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) Properties(java.util.Properties) Test(org.junit.Test)

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