use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testLazyInitialization.
@Test
public void testLazyInitialization() {
KnowsIfInstantiated.clearInstantiationRecord();
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("x1.(class)", KnowsIfInstantiated.class.getName());
p.setProperty("x1.(lazy-init)", "true");
assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
lbf.preInstantiateSingletons();
assertTrue("singleton not instantiated", !KnowsIfInstantiated.wasInstantiated());
lbf.getBean("x1");
assertTrue("singleton was instantiated", KnowsIfInstantiated.wasInstantiated());
}
use of org.springframework.beans.factory.support.PropertiesBeanDefinitionReader in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testInitializedFactoryBeanFoundByNonEagerTypeMatching.
@Test
public void testInitializedFactoryBeanFoundByNonEagerTypeMatching() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
Properties p = new Properties();
p.setProperty("x1.(class)", DummyFactory.class.getName());
// Reset static state
DummyFactory.reset();
p.setProperty("x1.singleton", "false");
(new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
lbf.preInstantiateSingletons();
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
assertEquals(1, beanNames.length);
assertEquals("x1", beanNames[0]);
assertTrue(lbf.containsSingleton("x1"));
assertTrue(lbf.containsBean("x1"));
assertTrue(lbf.containsBean("&x1"));
assertTrue(lbf.containsLocalBean("x1"));
assertTrue(lbf.containsLocalBean("&x1"));
assertFalse(lbf.isSingleton("x1"));
assertTrue(lbf.isSingleton("&x1"));
assertTrue(lbf.isPrototype("x1"));
assertFalse(lbf.isPrototype("&x1"));
assertTrue(lbf.isTypeMatch("x1", TestBean.class));
assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
assertTrue(lbf.isTypeMatch("x1", Object.class));
assertTrue(lbf.isTypeMatch("&x1", Object.class));
assertEquals(TestBean.class, lbf.getType("x1"));
assertEquals(DummyFactory.class, lbf.getType("&x1"));
assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
lbf.registerAlias("x1", "x2");
assertTrue(lbf.containsBean("x2"));
assertTrue(lbf.containsBean("&x2"));
assertTrue(lbf.containsLocalBean("x2"));
assertTrue(lbf.containsLocalBean("&x2"));
assertFalse(lbf.isSingleton("x2"));
assertTrue(lbf.isSingleton("&x2"));
assertTrue(lbf.isPrototype("x2"));
assertFalse(lbf.isPrototype("&x2"));
assertTrue(lbf.isTypeMatch("x2", TestBean.class));
assertFalse(lbf.isTypeMatch("&x2", TestBean.class));
assertTrue(lbf.isTypeMatch("&x2", DummyFactory.class));
assertTrue(lbf.isTypeMatch("x2", Object.class));
assertTrue(lbf.isTypeMatch("&x2", Object.class));
assertEquals(TestBean.class, lbf.getType("x2"));
assertEquals(DummyFactory.class, lbf.getType("&x2"));
assertEquals(1, lbf.getAliases("x1").length);
assertEquals("x2", lbf.getAliases("x1")[0]);
assertEquals(1, lbf.getAliases("&x1").length);
assertEquals("&x2", lbf.getAliases("&x1")[0]);
assertEquals(1, lbf.getAliases("x2").length);
assertEquals("x1", lbf.getAliases("x2")[0]);
assertEquals(1, lbf.getAliases("&x2").length);
assertEquals("&x1", lbf.getAliases("&x2")[0]);
}
Aggregations