use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method testNonLenientDependencyMatching.
@Test
public void testNonLenientDependencyMatching() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONSTRUCTOR_ARG_CONTEXT);
AbstractBeanDefinition bd = (AbstractBeanDefinition) xbf.getBeanDefinition("lenientDependencyTestBean");
bd.setLenientConstructorResolution(false);
try {
xbf.getBean("lenientDependencyTestBean");
fail("Should have thrown BeanCreationException");
} catch (BeanCreationException ex) {
// expected
ex.printStackTrace();
assertTrue(ex.getMostSpecificCause().getMessage().contains("Ambiguous"));
}
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.
the class ConfigurationClassParser method parse.
public void parse(Set<BeanDefinitionHolder> configCandidates) {
this.deferredImportSelectors = new LinkedList<>();
for (BeanDefinitionHolder holder : configCandidates) {
BeanDefinition bd = holder.getBeanDefinition();
try {
if (bd instanceof AnnotatedBeanDefinition) {
parse(((AnnotatedBeanDefinition) bd).getMetadata(), holder.getBeanName());
} else if (bd instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) bd).hasBeanClass()) {
parse(((AbstractBeanDefinition) bd).getBeanClass(), holder.getBeanName());
} else {
parse(bd.getBeanClassName(), holder.getBeanName());
}
} catch (BeanDefinitionStoreException ex) {
throw ex;
} catch (Throwable ex) {
throw new BeanDefinitionStoreException("Failed to parse configuration class [" + bd.getBeanClassName() + "]", ex);
}
}
processDeferredImportSelectors();
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.
the class MBeanExportBeanDefinitionParser method parseInternal.
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(AnnotationMBeanExporter.class);
// Mark as infrastructure bean and attach source location.
builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
builder.getRawBeanDefinition().setSource(parserContext.extractSource(element));
String defaultDomain = element.getAttribute(DEFAULT_DOMAIN_ATTRIBUTE);
if (StringUtils.hasText(defaultDomain)) {
builder.addPropertyValue("defaultDomain", defaultDomain);
}
String serverBeanName = element.getAttribute(SERVER_ATTRIBUTE);
if (StringUtils.hasText(serverBeanName)) {
builder.addPropertyReference("server", serverBeanName);
} else {
AbstractBeanDefinition specialServer = MBeanServerBeanDefinitionParser.findServerForSpecialEnvironment();
if (specialServer != null) {
builder.addPropertyValue("server", specialServer);
}
}
String registration = element.getAttribute(REGISTRATION_ATTRIBUTE);
RegistrationPolicy registrationPolicy = RegistrationPolicy.FAIL_ON_EXISTING;
if (REGISTRATION_IGNORE_EXISTING.equals(registration)) {
registrationPolicy = RegistrationPolicy.IGNORE_EXISTING;
} else if (REGISTRATION_REPLACE_EXISTING.equals(registration)) {
registrationPolicy = RegistrationPolicy.REPLACE_EXISTING;
}
builder.addPropertyValue("registrationPolicy", registrationPolicy);
return builder.getBeanDefinition();
}
use of org.springframework.beans.factory.support.AbstractBeanDefinition in project spring-framework by spring-projects.
the class BeanAnnotationAttributePropagationTests method beanDef.
private AbstractBeanDefinition beanDef(Class<?> configClass) {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("config", new RootBeanDefinition(configClass));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(factory);
return (AbstractBeanDefinition) factory.getBeanDefinition("foo");
}
Aggregations