use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByNameWithNoDependencyCheck.
@Test
public void testAutowireBeanByNameWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spous", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
assertNull(bean.getSpouse());
}
use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testBeanPostProcessorWithWrappedObjectAndDisposableBean.
@Test
public void testBeanPostProcessorWithWrappedObjectAndDisposableBean() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(BeanWithDisposableBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) {
return new TestBean();
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) {
return bean;
}
});
BeanWithDisposableBean.closed = false;
lbf.preInstantiateSingletons();
lbf.destroySingletons();
assertTrue("Destroy method invoked", BeanWithDisposableBean.closed);
}
use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testPrototypeCreationWithDependencyCheckIsFastEnough.
@Test
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
Assume.notLogging(factoryLog);
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class);
rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
lbf.registerBeanDefinition("test", rbd);
lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor());
StopWatch sw = new StopWatch();
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
lbf.getBean("test");
}
sw.stop();
// System.out.println(sw.getTotalTimeMillis());
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testSmartInitFactory.
@Test
public void testSmartInitFactory() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.registerBeanDefinition("test", new RootBeanDefinition(EagerInitFactory.class));
lbf.preInstantiateSingletons();
EagerInitFactory factory = (EagerInitFactory) lbf.getBean("&test");
assertTrue(factory.initialized);
}
use of org.springframework.beans.factory.support.RootBeanDefinition in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testBeanDefinitionOverridingNotAllowed.
@Test
public void testBeanDefinitionOverridingNotAllowed() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.setAllowBeanDefinitionOverriding(false);
lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
try {
lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
fail("Should have thrown BeanDefinitionStoreException");
} catch (BeanDefinitionStoreException ex) {
assertEquals("test", ex.getBeanName());
// expected
}
}
Aggregations