use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class ComponentScanWithBasePackagesAndValueAlias method viaBeanRegistration.
@Test
public void viaBeanRegistration() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("componentScanAnnotatedConfig", genericBeanDefinition(ComponentScanAnnotatedConfig.class).getBeanDefinition());
bf.registerBeanDefinition("configurationClassPostProcessor", genericBeanDefinition(ConfigurationClassPostProcessor.class).getBeanDefinition());
GenericApplicationContext ctx = new GenericApplicationContext(bf);
ctx.refresh();
ctx.getBean(ComponentScanAnnotatedConfig.class);
ctx.getBean(TestBean.class);
assertThat("config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfig"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered " + "as bean definition did not trigger component scanning as expected", ctx.containsBean("fooServiceImpl"), is(true));
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultInitAndDestroyMethodsDefined.
@Test
public void testDefaultInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertTrue("bean should have been initialized", bean.isInitialized());
context.close();
assertTrue("bean should have been destroyed", bean.isDestroyed());
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultAutowire.
@Test
public void testDefaultAutowire() {
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);
assertNull("no dependencies should have been autowired", bean.getConstructorDependency());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency1());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
}
use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.
the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultNonExistingInitAndDestroyMethodsDefined.
@Test
public void testDefaultNonExistingInitAndDestroyMethodsDefined() {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.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 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());
}
Aggregations