Search in sources :

Example 56 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)

Example 57 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project grails-core by grails.

the class GrailsPlaceholderConfigurer method doProcessProperties.

@Override
protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess, StringValueResolver valueResolver) {
    BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) {

        @Override
        protected void visitMap(Map<?, ?> mapVal) {
            if (mapVal instanceof Config)
                return;
            super.visitMap(mapVal);
        }
    };
    String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
    for (String curName : beanNames) {
        // to avoid failing on unresolvable placeholders in properties file locations.
        if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
            BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (Exception ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage(), ex);
            }
        }
    }
    // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
    beanFactoryToProcess.resolveAliases(valueResolver);
    // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
    beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
}
Also used : BeanDefinitionVisitor(org.springframework.beans.factory.config.BeanDefinitionVisitor) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) Config(grails.config.Config) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Map(java.util.Map) IOException(java.io.IOException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException)

Example 58 with BeanDefinitionStoreException

use of org.springframework.beans.factory.BeanDefinitionStoreException in project cas by apereo.

the class BeanDefinitionStoreFailureAnalyzerTests method createFailure.

private BeanDefinitionStoreException createFailure() {
    val bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", genericBeanDefinition(CasServerProperties.class).addPropertyValue("name", "${not.defined}").getBeanDefinition());
    val ppc = new PropertySourcesPlaceholderConfigurer();
    try {
        ppc.postProcessBeanFactory(bf);
    } catch (final BeanDefinitionStoreException e) {
        return e;
    }
    return null;
}
Also used : lombok.val(lombok.val) CasServerProperties(org.apereo.cas.configuration.model.core.CasServerProperties) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer)

Example 59 with BeanDefinitionStoreException

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

the class SpringServiceBuilderFactory method getApplicationContext.

/**
 * This is factored out to permit use in a unit test.
 *
 * @param additionalFilePathnames
 * @return
 */
public static ApplicationContext getApplicationContext(List<String> additionalFilePathnames) {
    BusApplicationContext busApplicationContext = BusFactory.getDefaultBus().getExtension(BusApplicationContext.class);
    GenericApplicationContext appContext = new GenericApplicationContext(busApplicationContext);
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
    List<URL> urls = ClassLoaderUtils.getResources("META-INF/cxf/java2wsbeans.xml", SpringServiceBuilderFactory.class);
    for (URL url : urls) {
        reader.loadBeanDefinitions(new UrlResource(url));
    }
    for (String pathname : additionalFilePathnames) {
        try {
            reader.loadBeanDefinitions(new FileSystemResource(pathname));
        } catch (BeanDefinitionStoreException bdse) {
            throw new ToolException("Unable to open bean definition file " + pathname, bdse.getCause());
        }
    }
    appContext.refresh();
    return appContext;
}
Also used : BusApplicationContext(org.apache.cxf.bus.spring.BusApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) UrlResource(org.springframework.core.io.UrlResource) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) ToolException(org.apache.cxf.tools.common.ToolException) URL(java.net.URL)

Aggregations

BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)59 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)18 Test (org.junit.Test)12 IOException (java.io.IOException)11 LinkedHashSet (java.util.LinkedHashSet)7 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)6 HashSet (java.util.HashSet)5 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)5 BeanDefinitionVisitor (org.springframework.beans.factory.config.BeanDefinitionVisitor)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 MockServletContext (org.springframework.mock.web.test.MockServletContext)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)4 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)4 Resource (org.springframework.core.io.Resource)4 Method (java.lang.reflect.Method)3 LinkedHashMap (java.util.LinkedHashMap)3