Search in sources :

Example 46 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project syndesis by syndesisio.

the class ODataCreateEntityConnectorAutoConfiguration method postConstructODataCreateEntityComponent.

@PostConstruct
public void postConstructODataCreateEntityComponent() {
    Map<String, Object> parameters = new HashMap<>();
    for (Map.Entry<String, ODataCreateEntityConnectorConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
        parameters.clear();
        ODataCreateEntityComponent connector = new ODataCreateEntityComponent(entry.getKey());
        connector.setCamelContext(camelContext);
        try {
            IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
            CamelPropertiesHelper.setCamelProperties(camelContext, connector, parameters, false);
            connector.setOptions(parameters);
            if (ObjectHelper.isNotEmpty(customizers)) {
                for (ConnectorCustomizer<ODataCreateEntityComponent> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId) ? HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.odata-create-entity." + entry.getKey() + ".customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.odata-create-entity." + entry.getKey() + ".customizer");
                    if (useCustomizer) {
                        LOGGER.debug("Configure connector {}, with customizer {}", connector, customizer);
                        customizer.customize(connector);
                    }
                }
            }
            camelContext.addComponent(entry.getKey(), connector);
        } catch (Exception e) {
            throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
        }
    }
}
Also used : ODataCreateEntityComponent(io.syndesis.connector.odata.ODataCreateEntityComponent) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HashMap(java.util.HashMap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HasId(org.apache.camel.spi.HasId) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 47 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project syndesis by syndesisio.

the class ODataDeleteEntityConnectorAutoConfiguration method postConstructODataDeleteEntityComponent.

@PostConstruct
public void postConstructODataDeleteEntityComponent() {
    Map<String, Object> parameters = new HashMap<>();
    for (Map.Entry<String, ODataDeleteEntityConnectorConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
        parameters.clear();
        ODataDeleteEntityComponent connector = new ODataDeleteEntityComponent(entry.getKey());
        connector.setCamelContext(camelContext);
        try {
            IntrospectionSupport.getProperties(entry.getValue(), parameters, null, false);
            CamelPropertiesHelper.setCamelProperties(camelContext, connector, parameters, false);
            connector.setOptions(parameters);
            if (ObjectHelper.isNotEmpty(customizers)) {
                for (ConnectorCustomizer<ODataDeleteEntityComponent> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId) ? HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.odata-delete-entity." + entry.getKey() + ".customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.odata-delete-entity." + entry.getKey() + ".customizer");
                    if (useCustomizer) {
                        LOGGER.debug("Configure connector {}, with customizer {}", connector, customizer);
                        customizer.customize(connector);
                    }
                }
            }
            camelContext.addComponent(entry.getKey(), connector);
        } catch (Exception e) {
            throw new BeanCreationException(entry.getKey(), e.getMessage(), e);
        }
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ODataDeleteEntityComponent(io.syndesis.connector.odata.ODataDeleteEntityComponent) HashMap(java.util.HashMap) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HasId(org.apache.camel.spi.HasId) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

Example 48 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project ma-core-public by infiniteautomation.

the class DwrSpringServlet method init.

/* (non-Javadoc)
     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
     */
public void init(ServletConfig servletConfig) throws ServletException {
    super.init(servletConfig);
    ServletContext servletContext = servletConfig.getServletContext();
    try {
        WebApplicationContext webappContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        container = new SpringContainer();
        container.setBeanFactory(webappContext);
        ContainerUtil.setupDefaults(container, servletConfig);
        ContainerUtil.setupFromServletConfig(container, servletConfig);
        container.setupFinished();
        webContextBuilder = StartupUtil.initWebContext(servletConfig, servletContext, container);
        StartupUtil.initServerContext(servletConfig, servletContext, container);
        ContainerUtil.prepareForWebContextFilter(servletContext, servletConfig, container, webContextBuilder, this);
        // retrieve the configurators from Spring (loaded by the ContextLoaderListener)
        try {
            configurators.add(webappContext.getBean(DwrNamespaceHandler.DEFAULT_SPRING_CONFIGURATOR_ID));
        } catch (NoSuchBeanDefinitionException ex) {
            throw new ServletException("No DWR configuration was found in your application context, make sure to define one", ex);
        }
        if (includeDefaultConfig) {
            ContainerUtil.configureFromSystemDwrXml(container);
        }
        ContainerUtil.configureFromInitParams(container, servletConfig);
        ContainerUtil.configure(container, configurators);
        ContainerUtil.publishContainer(container, servletConfig);
    } catch (InstantiationException ex) {
        throw new BeanCreationException("Failed to instansiate", ex);
    } catch (IllegalAccessException ex) {
        throw new BeanCreationException("Access error", ex);
    } catch (Exception ex) {
        log.fatal("init failed", ex);
        throw new ServletException(ex);
    } finally {
        webContextBuilder.unset();
    }
}
Also used : ServletException(javax.servlet.ServletException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) ServletContext(javax.servlet.ServletContext) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 49 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project spring-integration-aws by spring-projects.

the class SqsMessageDrivenChannelAdapter method onInit.

@Override
protected void onInit() {
    super.onInit();
    this.listenerContainer = this.simpleMessageListenerContainerFactory.createSimpleMessageListenerContainer();
    if (this.queueStopTimeout != null) {
        this.listenerContainer.setQueueStopTimeout(this.queueStopTimeout);
    }
    this.listenerContainer.setMessageHandler(new IntegrationQueueMessageHandler());
    try {
        this.listenerContainer.afterPropertiesSet();
    } catch (Exception e) {
        throw new BeanCreationException("Cannot instantiate 'SimpleMessageListenerContainer'", e);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 50 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project BroadleafCommerce by BroadleafCommerce.

the class AbstractMergeBeanPostProcessor method processPackage.

protected Object processPackage(BeanPackage beanPackage, Object bean, String beanName) {
    String sourceRef = beanPackage.getSourceRef();
    String targetRef = beanPackage.getTargetRef();
    Placement placement = beanPackage.getPlacement();
    int position = beanPackage.getPosition();
    MergeBeanStatusProvider statusProvider = beanPackage.getStatusProvider();
    Object sourceItem = null;
    Object targetItem = null;
    if (beanName.equals(targetRef)) {
        targetItem = bean;
        if (!StringUtils.isEmpty(sourceRef)) {
            sourceItem = applicationContext.getBean(sourceRef);
        } else {
            throw new IllegalArgumentException("Must declare an source reference value. See #setCollectionRef()");
        }
    }
    if (sourceItem != null && targetItem != null) {
        if (statusProvider != null && !statusProvider.isProcessingEnabled(targetItem, beanName, applicationContext)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace(String.format("Not performing post-processing on targetRef [%s] because the registered " + "status provider [%s] returned false", targetRef, statusProvider.getClass().getSimpleName()));
            }
            return bean;
        }
        if (targetItem instanceof ListFactoryBean || targetItem instanceof List) {
            try {
                if (sourceItem instanceof List) {
                    addListToList(targetItem, sourceItem, placement, position);
                } else {
                    if (sourceItem instanceof Collection) {
                        throw new IllegalArgumentException(String.format("Attempting to merge a collection of type " + "%s into a target list. Only source collections of type ListFactoryBean or List " + "may be used.", sourceItem.getClass().getName()));
                    }
                    addItemToList(targetItem, sourceItem, placement, position);
                }
            } catch (Exception e) {
                throw new BeanCreationException(e.getMessage());
            }
        } else if (targetItem instanceof SetFactoryBean || targetItem instanceof Set) {
            try {
                if (sourceItem instanceof Set) {
                    addSetToSet(targetItem, sourceItem, placement, position);
                } else {
                    if (sourceItem instanceof Collection) {
                        throw new IllegalArgumentException(String.format("Attempting to merge a collection of type " + "%s into a target set. Only source collections of type SetFactoryBean or Set " + "may be used.", sourceItem.getClass().getName()));
                    }
                    addItemToSet(targetItem, sourceItem, placement, position);
                }
            } catch (Exception e) {
                throw new BeanCreationException(e.getMessage());
            }
        } else if (targetItem instanceof MapFactoryBean || targetItem instanceof Map) {
            try {
                if (sourceItem instanceof Map) {
                    addMapToMap(targetItem, (Map) sourceItem, placement, position);
                } else {
                    throw new IllegalArgumentException(String.format("Attempting to merge an item of type " + "%s into a target map. Only source items of type MapFactoryBean or Map " + "may be used.", sourceItem.getClass().getName()));
                }
            } catch (Exception e) {
                throw new BeanCreationException(e.getMessage());
            }
        } else {
            throw new IllegalArgumentException("Bean (" + beanName + ") is specified as a merge target, " + "but is not" + " of type ListFactoryBean, SetFactoryBean or MapFactoryBean");
        }
    }
    return bean;
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) SetFactoryBean(org.springframework.beans.factory.config.SetFactoryBean) Set(java.util.Set) ListFactoryBean(org.springframework.beans.factory.config.ListFactoryBean) MapFactoryBean(org.springframework.beans.factory.config.MapFactoryBean) BeansException(org.springframework.beans.BeansException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

BeanCreationException (org.springframework.beans.factory.BeanCreationException)133 Test (org.junit.Test)30 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)18 BeansException (org.springframework.beans.BeansException)16 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 IOException (java.io.IOException)12 Map (java.util.Map)12 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)12 Test (org.junit.jupiter.api.Test)11 HashMap (java.util.HashMap)9 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)9 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)8 ArrayList (java.util.ArrayList)7 PostConstruct (javax.annotation.PostConstruct)7 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)7 Bean (org.springframework.context.annotation.Bean)7 HasId (org.apache.camel.spi.HasId)6 BeanCurrentlyInCreationException (org.springframework.beans.factory.BeanCurrentlyInCreationException)6 BeanDefinitionStoreException (org.springframework.beans.factory.BeanDefinitionStoreException)6 BeanWrapperImpl (org.springframework.beans.BeanWrapperImpl)5