Package org.springframework.beans.factory.support

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


          .addPropertyValue("favouriteColour", "Blue")
          .addPropertyValue("jobTitle", "Grand Poobah")
          .getBeanDefinition();
      factory.registerBeanDefinition("testBean", beanDef);
      factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
      factory.preInstantiateSingletons();
      fail("Should have thrown BeanCreationException");
    }
    catch (BeanCreationException ex) {
      String message = ex.getCause().getMessage();
      assertTrue(message.contains("Property"));
View Full Code Here


        .addPropertyValue("favouriteColour", "Blue")
        .addPropertyValue("jobTitle", "Grand Poobah")
        .getBeanDefinition();
    factory.registerBeanDefinition("testBean", beanDef);
    factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
    factory.preInstantiateSingletons();
    RequiredTestBean bean = (RequiredTestBean) factory.getBean("testBean");
    assertEquals(24, bean.getAge());
    assertEquals("Blue", bean.getFavouriteColour());
  }
View Full Code Here

    factory.registerBeanDefinition("testBean", beanDef);
    factory.registerBeanDefinition("testBeanFactory", new RootBeanDefinition(RequiredTestBeanFactory.class));
    RequiredAnnotationBeanPostProcessor bpp = new RequiredAnnotationBeanPostProcessor();
    bpp.setBeanFactory(factory);
    factory.addBeanPostProcessor(bpp);
    factory.preInstantiateSingletons();
  }


  @Retention(RetentionPolicy.RUNTIME)
  @Target(ElementType.METHOD)
View Full Code Here

  private void assertExceptionMessageForMisconfiguredFactoryMethod(BeanDefinition bd, String expectedMessage) {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("foo", bd);

    try {
      factory.preInstantiateSingletons();
      fail("should have failed with BeanCreationException due to incorrectly invoked factory method");
    } catch (BeanCreationException ex) {
      assertThat(ex.getMessage(), equalTo(expectedMessage));
    }
  }
View Full Code Here

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

  @Test
  public void testLazyInitialization() {
View Full Code Here

    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

    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

  public void testIgnoreDefaultLifecycleMethods() throws Exception {
    try {
      DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
      new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
          new ClassPathResource("ignoreDefaultLifecycleMethods.xml", getClass()));
      bf.preInstantiateSingletons();
      bf.destroySingletons();
    }
    catch (Exception ex) {
      ex.printStackTrace();
      fail("Should ignore non-existent default lifecycle methods");
View Full Code Here

    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

  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.