use of org.springframework.context.support.GenericApplicationContext 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.context.support.GenericApplicationContext 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.context.support.GenericApplicationContext 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.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class ConfigurationClassProcessingTests method configWithSetWithProviderImplementation.
// SPR-11830
@Test
public void configWithSetWithProviderImplementation() {
GenericApplicationContext ac = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
ac.registerBeanDefinition("config", new RootBeanDefinition(ConfigWithSetWithProviderImplementation.class));
ac.refresh();
assertSame(ac.getBean("customName"), ConfigWithSetWithProviderImplementation.set);
}
use of org.springframework.context.support.GenericApplicationContext 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