Examples of preInstantiateSingletons()


Examples of org.springframework.beans.factory.config.ConfigurableListableBeanFactory.preInstantiateSingletons()

        ConfigurableListableBeanFactory factory = new XmlBeanFactory(
                new FileSystemResource(
                        "./ch5/src/conf/interaction/shutdownHook.xml"));

        // make sure the shutdown hook is created
        factory.preInstantiateSingletons();

        DestructiveBeanWithInterface bean = (DestructiveBeanWithInterface) factory.getBean("destructiveBean");
    }
}
View Full Code Here

Examples of org.springframework.beans.factory.config.ConfigurableListableBeanFactory.preInstantiateSingletons()

        // Check for listener beans and register them.
        registerListeners();

        // Instantiate all remaining (non-lazy-init) singletons.
        beanFactory.preInstantiateSingletons();

        // Last step: publish corresponding event.
        finishRefresh();
      }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    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());
  }

  public void testLazyInitialization() {
    KnowsIfInstantiated.clearInstantiationRecord();
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    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());
  }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    p.setProperty("x1.singleton", "false");
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    assertEquals(TestBean.class, lbf.getType("x1"));
    lbf.preInstantiateSingletons();

    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    lbf.getBean("x1");
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertTrue(lbf.containsBean("x1"));
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    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]);
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

          // Keep compiler happy about return
          throw new IllegalStateException();
        }
      }
    });
    lbf.preInstantiateSingletons();
    TestBean tb = (TestBean) lbf.getBean("test");
    assertEquals("Name was set on field by IAPP", nameSetOnField, tb.getName());
    if (!skipPropertyPopulation) {
      assertEquals("Property value still set", ageSetByPropertyValue, tb.getAge());
    }
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(xbf);
    reader.loadBeanDefinitions(new ClassPathResource("factory-methods.xml", getClass()));

    InstanceFactory.count = 0;
    xbf.preInstantiateSingletons();
    assertEquals(1, InstanceFactory.count);
    FactoryMethods fm = (FactoryMethods) xbf.getBean("instanceFactoryMethodWithoutArgs");
    assertEquals("instanceFactory", fm.getTestBean().getName());
    assertEquals(1, InstanceFactory.count);
    FactoryMethods fm2 = (FactoryMethods) xbf.getBean("instanceFactoryMethodWithoutArgs");
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

    String[] names = xbf.getBeanNamesForType(FactoryMethods.class);
    assertTrue(!Arrays.asList(names).contains("listInstance"));
    names = xbf.getBeanNamesForType(List.class);
    assertTrue(Arrays.asList(names).contains("listInstance"));

    xbf.preInstantiateSingletons();
    assertTrue(List.class.isAssignableFrom(xbf.getType("listInstance")));
    names = xbf.getBeanNamesForType(FactoryMethods.class);
    assertTrue(!Arrays.asList(names).contains("listInstance"));
    names = xbf.getBeanNamesForType(List.class);
    assertTrue(Arrays.asList(names).contains("listInstance"));
View Full Code Here

Examples of org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons()

  public void testBeanDefinitionRemoval() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.setAllowBeanDefinitionOverriding(false);
    lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
    lbf.registerAlias("test", "test2");
    lbf.preInstantiateSingletons();
    lbf.removeBeanDefinition("test");
    lbf.removeAlias("test2");
    lbf.registerBeanDefinition("test", new RootBeanDefinition(NestedTestBean.class));
    lbf.registerAlias("test", "test2");
    assertTrue(lbf.getBean("test") instanceof NestedTestBean);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.