Search in sources :

Example 91 with BeansException

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

the class OutboundResponseTypeTests method testMutuallyExclusivityInMethodAndMethodExpression.

@Test
public void testMutuallyExclusivityInMethodAndMethodExpression() throws Exception {
    try {
        new ClassPathXmlApplicationContext("OutboundResponseTypeTests-context-fail.xml", this.getClass()).close();
        fail("Expected BeansException");
    } catch (BeansException e) {
        assertTrue(e instanceof BeanDefinitionParsingException);
        assertTrue(e.getMessage().contains("The 'expected-response-type' " + "and 'expected-response-type-expression' are mutually exclusive"));
    }
}
Also used : BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) BeansException(org.springframework.beans.BeansException) Test(org.junit.Test)

Example 92 with BeansException

use of org.springframework.beans.BeansException in project alien4cloud by alien4cloud.

the class ReflectionUtil method mergeObject.

/**
 * Merge object from an object to another. Failsafe : resist to invalid property.
 *
 * @param from source of the update
 * @param to target of the update
 * @param ignoreNullValue indicate if we should merge null value
 * @param ignores properties names that should be ignored
 */
public static void mergeObject(Object from, Object to, boolean ignoreNullValue, Set<String> ignores) {
    try {
        Map<String, Object> settablePropertiesMap = Maps.newHashMap();
        PropertyDescriptor[] propertyDescriptors = getPropertyDescriptors(from.getClass());
        for (PropertyDescriptor property : propertyDescriptors) {
            if (property.getReadMethod() == null || property.getWriteMethod() == null) {
                continue;
            }
            Object value = property.getReadMethod().invoke(from);
            if ((value != null || !ignoreNullValue) && !ignores.contains(property.getName())) {
                settablePropertiesMap.put(property.getName(), value);
            }
        }
        for (Map.Entry<String, Object> settableProperty : settablePropertiesMap.entrySet()) {
            // Set new values
            String propertyName = settableProperty.getKey();
            Object propertyValue = settableProperty.getValue();
            setPropertyValue(to, propertyName, propertyValue);
        }
    } catch (IllegalAccessException | InvocationTargetException | BeansException e) {
        throw new InvalidArgumentException("Cannot merge object", e);
    }
}
Also used : InvalidArgumentException(alien4cloud.exception.InvalidArgumentException) PropertyDescriptor(java.beans.PropertyDescriptor) HashMap(java.util.HashMap) Map(java.util.Map) InvocationTargetException(java.lang.reflect.InvocationTargetException) BeansException(org.springframework.beans.BeansException)

Example 93 with BeansException

use of org.springframework.beans.BeansException in project commons by craftercms.

the class EBusBeanAutoConfiguration method onApplicationEvent.

@Override
public void onApplicationEvent(final ContextRefreshedEvent contextRefreshedEvent) {
    ApplicationContext ctx = contextRefreshedEvent.getApplicationContext();
    if (applicationContext != ctx) {
        return;
    }
    if (null == beanResolver) {
        beanResolver = new BeanFactoryResolver(ctx);
    }
    if (null == conversionService) {
        try {
            conversionService = ctx.getBean(ConsumerBeanAutoConfiguration.REACTOR_CONVERSION_SERVICE_BEAN_NAME, ConversionService.class);
        } catch (BeansException be) {
        // TODO: log that conversion service is not found.
        }
    }
    synchronized (this) {
        if (started) {
            return;
        }
        Set<Method> methods;
        Class<?> type;
        for (String beanName : ctx.getBeanDefinitionNames()) {
            type = ctx.getType(beanName);
            methods = findHandlerMethods(type, LISTENER_METHOD_FILTER);
            if (methods != null && methods.size() > 0) {
                wireBean(ctx.getBean(beanName), methods);
            }
        }
        started = true;
    }
}
Also used : BeanFactoryResolver(org.springframework.context.expression.BeanFactoryResolver) ApplicationContext(org.springframework.context.ApplicationContext) ConversionService(org.springframework.core.convert.ConversionService) Method(java.lang.reflect.Method) BeansException(org.springframework.beans.BeansException)

Example 94 with BeansException

use of org.springframework.beans.BeansException in project dubbo-faker by moyada.

the class SharinganMonitorAutoConfiguration method setBeanFactory.

@Override
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
    ScanPackages bean;
    try {
        bean = beanFactory.getBean(ScanPackages.class);
    } catch (BeansException e) {
        return;
    }
    this.basePackages = bean.getBasePackages();
    if (beanFactory instanceof DefaultListableBeanFactory) {
        ((DefaultListableBeanFactory) beanFactory).removeBeanDefinition(ScanPackages.BEAN_NAME);
        ((DefaultListableBeanFactory) beanFactory).destroyBean(bean);
    }
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) ScanPackages(io.moyada.spring.boot.sharingan.context.ScanPackages) BeansException(org.springframework.beans.BeansException)

Example 95 with BeansException

use of org.springframework.beans.BeansException in project geronimo-xbean by apache.

the class NamedConstructorArgs method processParameters.

public void processParameters(BeanDefinitionHolder definitionHolder, MappingMetaData metadata) throws BeansException {
    // this only works if we have an abstsract bean definition
    if (!(definitionHolder.getBeanDefinition() instanceof AbstractBeanDefinition)) {
        return;
    }
    AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) definitionHolder.getBeanDefinition();
    ConstructorArgumentValues constructorArgumentValues = beanDefinition.getConstructorArgumentValues();
    // if this bean already has constructor arguments defined, don't mess with them
    if (constructorArgumentValues.getArgumentCount() > 0) {
        return;
    }
    // try to get a list of constructor arg names to use
    ConstructionInfo constructionInfo = selectConstructionMethod(beanDefinition, metadata);
    if (constructionInfo == null) {
        return;
    }
    // remove each named property and add an indexed constructor arg
    MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
    String[] parameterNames = constructionInfo.parameterNames;
    Class[] parameterTypes = constructionInfo.parameterTypes;
    for (int i = 0; i < parameterNames.length; i++) {
        String parameterName = parameterNames[i];
        Class parameterType = parameterTypes[i];
        PropertyValue propertyValue = propertyValues.getPropertyValue(parameterName);
        if (propertyValue != null) {
            propertyValues.removePropertyValue(parameterName);
            constructorArgumentValues.addIndexedArgumentValue(i, propertyValue.getValue(), parameterType.getName());
        } else {
            Object defaultValue = defaultValues.get(new PropertyKey(parameterName, parameterType));
            if (defaultValue == null) {
                defaultValue = DEFAULT_VALUE.get(parameterType);
            }
            if (defaultValue instanceof FactoryBean) {
                try {
                    defaultValue = ((FactoryBean) defaultValue).getObject();
                } catch (Exception e) {
                    throw new FatalBeanException("Unable to get object value from bean factory", e);
                }
            }
            constructorArgumentValues.addIndexedArgumentValue(i, defaultValue, parameterType.getName());
        }
    }
// todo set any usable default values on the bean definition
}
Also used : AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) PropertyValue(org.springframework.beans.PropertyValue) FatalBeanException(org.springframework.beans.FatalBeanException) BeansException(org.springframework.beans.BeansException) ConstructorArgumentValues(org.springframework.beans.factory.config.ConstructorArgumentValues) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) FatalBeanException(org.springframework.beans.FatalBeanException) FactoryBean(org.springframework.beans.factory.FactoryBean)

Aggregations

BeansException (org.springframework.beans.BeansException)126 Test (org.junit.Test)24 ApplicationContext (org.springframework.context.ApplicationContext)22 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)18 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)16 Map (java.util.Map)15 ArrayList (java.util.ArrayList)13 BeanCreationException (org.springframework.beans.factory.BeanCreationException)11 HashMap (java.util.HashMap)10 BeanWrapper (org.springframework.beans.BeanWrapper)10 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 MalformedURLException (java.net.MalformedURLException)9 File (java.io.File)8 IOException (java.io.IOException)8 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)8 List (java.util.List)7 Method (java.lang.reflect.Method)6 LinkedHashSet (java.util.LinkedHashSet)6