Search in sources :

Example 41 with BeanCreationException

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

the class JdbcMessageHandlerParser method parseConsumer.

@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(JdbcMessageHandler.class);
    String dataSourceRef = element.getAttribute("data-source");
    String jdbcOperationsRef = element.getAttribute("jdbc-operations");
    boolean refToDataSourceSet = StringUtils.hasText(dataSourceRef);
    boolean refToJdbcOperationsSet = StringUtils.hasText(jdbcOperationsRef);
    if ((refToDataSourceSet && refToJdbcOperationsSet) || (!refToDataSourceSet && !refToJdbcOperationsSet)) {
        parserContext.getReaderContext().error("Exactly one of the attributes data-source or " + "simple-jdbc-operations should be set for the JDBC outbound-channel-adapter", source);
    }
    String query = IntegrationNamespaceUtils.getTextFromAttributeOrNestedElement(element, "query", parserContext);
    if (!StringUtils.hasText(query)) {
        throw new BeanCreationException("The query attribute is required");
    }
    if (!StringUtils.hasText(query)) {
        throw new BeanCreationException("The query attribute is required");
    }
    if (refToDataSourceSet) {
        builder.addConstructorArgReference(dataSourceRef);
    } else {
        builder.addConstructorArgReference(jdbcOperationsRef);
    }
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "sql-parameter-source-factory");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "prepared-statement-setter");
    builder.addConstructorArgValue(query);
    return builder.getBeanDefinition();
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder)

Example 42 with BeanCreationException

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

the class InboundChannelAdapterParserTests method pop3WithSearchTermStrategy.

@Test
public void pop3WithSearchTermStrategy() {
    try {
        new ClassPathXmlApplicationContext("org/springframework/integration/mail/config/InboundChannelAdapterParserTests-pop3Search-context.xml").close();
        fail("expected a parser error");
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("searchTermStrategy is only allowed with imap"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 43 with BeanCreationException

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

the class AbstractXmppInboundChannelAdapterParser method doParse.

@Override
protected AbstractBeanDefinition doParse(Element element, ParserContext parserContext, String channelName) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(getBeanClassName(element));
    IntegrationNamespaceUtils.configureHeaderMapper(element, builder, parserContext, DefaultXmppHeaderMapper.class, null);
    String connectionName = element.getAttribute("xmpp-connection");
    if (StringUtils.hasText(connectionName)) {
        builder.addConstructorArgReference(connectionName);
    } else if (parserContext.getRegistry().containsBeanDefinition(XmppNamespaceHandler.XMPP_CONNECTION_BEAN_NAME)) {
        builder.addConstructorArgReference(XmppNamespaceHandler.XMPP_CONNECTION_BEAN_NAME);
    } else {
        throw new BeanCreationException("You must either explicitly define which XMPP connection to use via " + "'xmpp-connection' attribute or have default XMPP connection bean registered under the name 'xmppConnection'" + "(e.g., <int-xmpp:xmpp-connection .../>). If 'id' is not provided the default will be 'xmppConnection'.");
    }
    builder.addPropertyReference("outputChannel", channelName);
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel");
    this.postProcess(element, parserContext, builder);
    return builder.getBeanDefinition();
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder)

Example 44 with BeanCreationException

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

the class AbstractXmppOutboundChannelAdapterParser method parseConsumer.

@Override
protected AbstractBeanDefinition parseConsumer(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(this.getHandlerClassName());
    IntegrationNamespaceUtils.configureHeaderMapper(element, builder, parserContext, DefaultXmppHeaderMapper.class, null);
    String connectionName = element.getAttribute("xmpp-connection");
    if (StringUtils.hasText(connectionName)) {
        builder.addConstructorArgReference(connectionName);
    } else if (parserContext.getRegistry().containsBeanDefinition(XmppNamespaceHandler.XMPP_CONNECTION_BEAN_NAME)) {
        builder.addConstructorArgReference(XmppNamespaceHandler.XMPP_CONNECTION_BEAN_NAME);
    } else {
        throw new BeanCreationException("You must either explicitly define which XMPP connection to use via " + "'xmpp-connection' attribute or have default XMPP connection bean registered under the name 'xmppConnection'" + "(e.g., <int-xmpp:xmpp-connection .../>). If 'id' is not provided the default will be 'xmppConnection'.");
    }
    return builder.getBeanDefinition();
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder)

Example 45 with BeanCreationException

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

the class SwaggerConnectorConnectorAutoConfiguration method postConstructSwaggerConnectorComponent.

@PostConstruct
public void postConstructSwaggerConnectorComponent() {
    Map<String, Object> parameters = new HashMap<>();
    for (Map.Entry<String, SwaggerConnectorConnectorConfigurationCommon> entry : configuration.getConfigurations().entrySet()) {
        parameters.clear();
        SwaggerConnectorComponent connector = new SwaggerConnectorComponent(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<SwaggerConnectorComponent> customizer : customizers) {
                    boolean useCustomizer = (customizer instanceof HasId) ? HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.swagger-operation." + entry.getKey() + ".customizer", ((HasId) customizer).getId()) : HierarchicalPropertiesEvaluator.evaluate(applicationContext.getEnvironment(), "camel.connector.customizer", "camel.connector.swagger-operation." + 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) HashMap(java.util.HashMap) SwaggerConnectorComponent(io.syndesis.connector.rest.swagger.SwaggerConnectorComponent) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HasId(org.apache.camel.spi.HasId) HashMap(java.util.HashMap) Map(java.util.Map) PostConstruct(javax.annotation.PostConstruct)

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