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"));
}
}
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);
}
}
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;
}
}
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);
}
}
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
}
Aggregations