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