use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireConstructor.
@Test
public void testAutowireConstructor() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireConstructorTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNotNull("constructor dependency should have been autowired", bean.getConstructorDependency());
assertEquals("cd", bean.getConstructorDependency().getName());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency1());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireByType.
@Test
public void testAutowireByType() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByTypeTests.xml");
try {
context.refresh();
fail("expected exception due to multiple matches for byType autowiring");
} catch (UnsatisfiedDependencyException ex) {
// expected
}
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultInitAndDestroyMethodsNotDefined.
@Test
public void testDefaultInitAndDestroyMethodsNotDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertFalse("bean should not have been initialized", bean.isInitialized());
context.close();
assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireByName.
@Test
public void testAutowireByName() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByNameTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNull("constructor dependency should not have been autowired", bean.getConstructorDependency());
assertNull("propertyDependency1 should not have been autowired", bean.getPropertyDependency1());
assertNotNull("propertyDependency2 should have been autowired", bean.getPropertyDependency2());
assertEquals("pd2", bean.getPropertyDependency2().getName());
}
use of org.springframework.beans.factory.xml.XmlBeanDefinitionReader in project spring-framework by spring-projects.
the class AutowiredConfigurationTests method testAutowiredSingleConstructorSupported.
@Test
public void testAutowiredSingleConstructorSupported() {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class));
GenericApplicationContext ctx = new GenericApplicationContext(factory);
ctx.registerBeanDefinition("config1", new RootBeanDefinition(AutowiredConstructorConfig.class));
ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
ctx.refresh();
assertSame(ctx.getBean(AutowiredConstructorConfig.class).colour, ctx.getBean(Colour.class));
}
Aggregations