use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testRegistrationOfManySingletonsIsFastEnough.
@Test(timeout = 1000)
public void testRegistrationOfManySingletonsIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("b", new RootBeanDefinition(B.class));
for (int i = 0; i < 100000; i++) {
bf.registerSingleton("a" + i, new A());
}
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByName.
@Test
public void testAutowireBeanByName() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertEquals(spouse, bean.getSpouse());
assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testUnreferencedSingletonWasInstantiated.
@Test
public void testUnreferencedSingletonWasInstantiated() {
KnowsIfInstantiated.clearInstantiationRecord();
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
lbf.preInstantiateSingletons();
assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testScopeInheritanceForChildBeanDefinitions.
@Test
public void testScopeInheritanceForChildBeanDefinitions() throws Exception {
RootBeanDefinition parent = new RootBeanDefinition();
parent.setScope("bonanza!");
AbstractBeanDefinition child = new ChildBeanDefinition("parent");
child.setBeanClass(TestBean.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("parent", parent);
factory.registerBeanDefinition("child", child);
BeanDefinition def = factory.getMergedBeanDefinition("child");
assertEquals("Child 'scope' not inherited", "bonanza!", def.getScope());
}
use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testEmpty.
@Test
public void testEmpty() {
ListableBeanFactory lbf = new DefaultListableBeanFactory();
assertTrue("No beans defined --> array != null", lbf.getBeanDefinitionNames() != null);
assertTrue("No beans defined after no arg constructor", lbf.getBeanDefinitionNames().length == 0);
assertTrue("No beans defined after no arg constructor", lbf.getBeanDefinitionCount() == 0);
}
Aggregations