Search in sources :

Example 81 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project tomee by apache.

the class SpringClassUnwrapper method getRealClass.

@Override
public Class<?> getRealClass(Object o) {
    if (AopUtils.isAopProxy(o) && (o instanceof Advised)) {
        Advised advised = (Advised) o;
        try {
            TargetSource targetSource = advised.getTargetSource();
            final Object target;
            try {
                target = targetSource.getTarget();
            } catch (BeanCreationException ex) {
                // be active on the current thread yet
                return getRealClassFromClass(targetSource.getTargetClass());
            }
            if (target == null) {
                Class<?> targetClass = AopUtils.getTargetClass(o);
                if (targetClass != null) {
                    return getRealClassFromClass(targetClass);
                }
            } else {
                return getRealClass(target);
            }
        } catch (Exception ex) {
        // ignore
        }
    } else if (ClassUtils.isCglibProxyClass(o.getClass())) {
        return getRealClassFromClass(AopUtils.getTargetClass(o));
    }
    return o.getClass();
}
Also used : TargetSource(org.springframework.aop.TargetSource) BeanCreationException(org.springframework.beans.factory.BeanCreationException) Advised(org.springframework.aop.framework.Advised) BeanCreationException(org.springframework.beans.factory.BeanCreationException)

Example 82 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project dubbo by alibaba.

the class ConfigTest method testMultiProtocolError.

@Test
public void testMultiProtocolError() {
    try {
        ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(ConfigTest.class.getPackage().getName().replace('.', '/') + "/multi-protocol-error.xml");
        ctx.start();
        ctx.stop();
        ctx.close();
    } catch (BeanCreationException e) {
        assertTrue(e.getMessage().contains("Found multi-protocols"));
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.jupiter.api.Test)

Example 83 with BeanCreationException

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

the class MongoDbCloudConfigBootstrapConfiguration method mongoClientOptions.

@Bean
public MongoClientOptions mongoClientOptions() {
    try {
        final MongoClientOptionsFactoryBean bean = new MongoClientOptionsFactoryBean();
        bean.setSocketTimeout(TIMEOUT);
        bean.setConnectTimeout(TIMEOUT);
        bean.afterPropertiesSet();
        return bean.getObject();
    } catch (final Exception e) {
        throw new BeanCreationException(e.getMessage(), e);
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) MongoClientOptionsFactoryBean(org.springframework.data.mongodb.core.MongoClientOptionsFactoryBean) BeanCreationException(org.springframework.beans.factory.BeanCreationException) MongoClientOptionsFactoryBean(org.springframework.data.mongodb.core.MongoClientOptionsFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 84 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project camel by apache.

the class HystrixAutoConfiguration method addHystrixConfigurations.

@PostConstruct
public void addHystrixConfigurations() {
    if (!(beanFactory instanceof ConfigurableBeanFactory)) {
        LOGGER.warn("BeanFactory is not of type ConfigurableBeanFactory");
        return;
    }
    final ConfigurableBeanFactory factory = (ConfigurableBeanFactory) beanFactory;
    final Map<String, Object> properties = new HashMap<>();
    for (Map.Entry<String, HystrixConfigurationCommon> entry : config.getConfigurations().entrySet()) {
        // clear the properties map for reuse
        properties.clear();
        // extract properties
        IntrospectionSupport.getProperties(entry.getValue(), properties, null, false);
        try {
            HystrixConfigurationDefinition definition = new HystrixConfigurationDefinition();
            IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(), definition, properties);
            // Registry the definition
            factory.registerSingleton(entry.getKey(), definition);
        } catch (Exception e) {
            throw new BeanCreationException(entry.getKey(), e);
        }
    }
}
Also used : ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) BeanCreationException(org.springframework.beans.factory.BeanCreationException) HashMap(java.util.HashMap) HystrixConfigurationCommon(org.apache.camel.model.HystrixConfigurationCommon) HashMap(java.util.HashMap) Map(java.util.Map) HystrixConfigurationDefinition(org.apache.camel.model.HystrixConfigurationDefinition) BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeansException(org.springframework.beans.BeansException) PostConstruct(javax.annotation.PostConstruct)

Example 85 with BeanCreationException

use of org.springframework.beans.factory.BeanCreationException in project camel by apache.

the class CamelNamespaceHandler method registerTemplates.

/**
     * Used for auto registering producer, fluent producer and consumer templates if not already defined in XML.
     */
protected void registerTemplates(Element element, ParserContext parserContext, String contextId) {
    boolean template = false;
    boolean fluentTemplate = false;
    boolean consumerTemplate = false;
    NodeList list = element.getChildNodes();
    int size = list.getLength();
    for (int i = 0; i < size; i++) {
        Node child = list.item(i);
        if (child instanceof Element) {
            Element childElement = (Element) child;
            String localName = childElement.getLocalName();
            if ("template".equals(localName)) {
                template = true;
            } else if ("fluentTemplate".equals(localName)) {
                fluentTemplate = true;
            } else if ("consumerTemplate".equals(localName)) {
                consumerTemplate = true;
            }
        }
    }
    if (!template) {
        // either we have not used template before or we have auto registered it already and therefore we
        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
        // since we have multiple camel contexts
        boolean existing = autoRegisterMap.get("template") != null;
        boolean inUse = false;
        try {
            inUse = parserContext.getRegistry().isBeanNameInUse("template");
        } catch (BeanCreationException e) {
            // Spring Eclipse Tooling may throw an exception when you edit the Spring XML online in Eclipse
            // when the isBeanNameInUse method is invoked, so ignore this and continue (CAMEL-2739)
            LOG.debug("Error checking isBeanNameInUse(template). This exception will be ignored", e);
        }
        if (!inUse || existing) {
            String id = "template";
            // auto create a template
            Element templateElement = element.getOwnerDocument().createElement("template");
            templateElement.setAttribute("id", id);
            BeanDefinitionParser parser = parserMap.get("template");
            BeanDefinition definition = parser.parse(templateElement, parserContext);
            // auto register it
            autoRegisterBeanDefinition(id, definition, parserContext, contextId);
        }
    }
    if (!fluentTemplate) {
        // either we have not used fluentTemplate before or we have auto registered it already and therefore we
        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
        // since we have multiple camel contexts
        boolean existing = autoRegisterMap.get("fluentTemplate") != null;
        boolean inUse = false;
        try {
            inUse = parserContext.getRegistry().isBeanNameInUse("fluentTemplate");
        } catch (BeanCreationException e) {
            // Spring Eclipse Tooling may throw an exception when you edit the Spring XML online in Eclipse
            // when the isBeanNameInUse method is invoked, so ignore this and continue (CAMEL-2739)
            LOG.debug("Error checking isBeanNameInUse(fluentTemplate). This exception will be ignored", e);
        }
        if (!inUse || existing) {
            String id = "fluentTemplate";
            // auto create a fluentTemplate
            Element templateElement = element.getOwnerDocument().createElement("fluentTemplate");
            templateElement.setAttribute("id", id);
            BeanDefinitionParser parser = parserMap.get("fluentTemplate");
            BeanDefinition definition = parser.parse(templateElement, parserContext);
            // auto register it
            autoRegisterBeanDefinition(id, definition, parserContext, contextId);
        }
    }
    if (!consumerTemplate) {
        // either we have not used template before or we have auto registered it already and therefore we
        // need it to allow to do it so it can remove the existing auto registered as there is now a clash id
        // since we have multiple camel contexts
        boolean existing = autoRegisterMap.get("consumerTemplate") != null;
        boolean inUse = false;
        try {
            inUse = parserContext.getRegistry().isBeanNameInUse("consumerTemplate");
        } catch (BeanCreationException e) {
            // Spring Eclipse Tooling may throw an exception when you edit the Spring XML online in Eclipse
            // when the isBeanNameInUse method is invoked, so ignore this and continue (CAMEL-2739)
            LOG.debug("Error checking isBeanNameInUse(consumerTemplate). This exception will be ignored", e);
        }
        if (!inUse || existing) {
            String id = "consumerTemplate";
            // auto create a template
            Element templateElement = element.getOwnerDocument().createElement("consumerTemplate");
            templateElement.setAttribute("id", id);
            BeanDefinitionParser parser = parserMap.get("consumerTemplate");
            BeanDefinition definition = parser.parse(templateElement, parserContext);
            // auto register it
            autoRegisterBeanDefinition(id, definition, parserContext, contextId);
        }
    }
}
Also used : BeanCreationException(org.springframework.beans.factory.BeanCreationException) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) Element(org.w3c.dom.Element) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

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