Examples of preInstantiateSingletons()


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

    p.setProperty("test.spouse(ref)", "singletonObject");
    p.setProperty("singletonObject.(class)", "org.springframework.beans.factory.config.PropertiesFactoryBean");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    Object singletonObject = new TestBean();
    lbf.registerSingleton("singletonObject", singletonObject);
    lbf.preInstantiateSingletons();

    assertTrue(lbf.isSingleton("singletonObject"));
    assertEquals(TestBean.class, lbf.getType("singletonObject"));
    TestBean test = (TestBean) lbf.getBean("test");
    assertEquals(singletonObject, lbf.getBean("singletonObject"));
View Full Code Here

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

      MutablePropertyValues pvs = new MutablePropertyValues();
      pvs.addPropertyValue(new PropertyValue("spouse", new RuntimeBeanReference("bean" + (i < 99 ? i + 1 : 0))));
      RootBeanDefinition bd = new RootBeanDefinition(TestBean.class, pvs);
      lbf.registerBeanDefinition("bean" + i, bd);
    }
    lbf.preInstantiateSingletons();
    for (int i = 0; i < 1000; i++) {
      TestBean bean = (TestBean) lbf.getBean("bean" + i);
      TestBean otherBean = (TestBean) lbf.getBean("bean" + (i < 99 ? i + 1 : 0));
      assertTrue(bean.getSpouse() == otherBean);
    }
View Full Code Here

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

  public void testCircularReferenceThroughAutowiring() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
    try {
      lbf.preInstantiateSingletons();
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException expected) {
    }
  }
View Full Code Here

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

  public void testCircularReferenceThroughFactoryBeanAutowiring() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
    try {
      lbf.preInstantiateSingletons();
      fail("Should have thrown UnsatisfiedDependencyException");
    }
    catch (UnsatisfiedDependencyException expected) {
    }
  }
View Full Code Here

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

  public void testAvoidCircularReferenceThroughAutowiring() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(ConstructorDependencyFactoryBean.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
    lbf.registerBeanDefinition("string",
        new RootBeanDefinition(String.class, RootBeanDefinition.AUTOWIRE_CONSTRUCTOR));
    lbf.preInstantiateSingletons();
  }

  public void testBeanDefinitionWithInterface() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(ITestBean.class));
View Full Code Here

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

  }

  public void testPrototypeFactoryBeanNotEagerlyCalled() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class));
    lbf.preInstantiateSingletons();
  }

  public void testLazyInitFactory() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(LazyInitFactory.class));
View Full Code Here

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

  }

  public void testLazyInitFactory() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test", new RootBeanDefinition(LazyInitFactory.class));
    lbf.preInstantiateSingletons();
    LazyInitFactory factory = (LazyInitFactory) lbf.getBean("&test");
    assertFalse(factory.initialized);
  }

  public void testSmartInitFactory() {
View Full Code Here

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

  }

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

  public void testPrototypeFactoryBeanNotEagerlyCalledInCaseOfBeanClassName() {
View Full Code Here

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

  public void testPrototypeFactoryBeanNotEagerlyCalledInCaseOfBeanClassName() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    lbf.registerBeanDefinition("test",
        new RootBeanDefinition(FactoryBeanThatShouldntBeCalled.class.getName(), null, null));
    lbf.preInstantiateSingletons();
  }

  public void testPrototypeWithArrayConversionForConstructor() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    List list = new ManagedList();
View Full Code Here

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

      public Object postProcessAfterInitialization(Object bean, String beanName) {
        return bean;
      }
    });
    BeanWithDisposableBean.closed = false;
    lbf.preInstantiateSingletons();
    lbf.destroySingletons();
    assertTrue("Destroy method invoked", BeanWithDisposableBean.closed);
  }

  public void testBeanPostProcessorWithWrappedObjectAndDestroyMethod() {
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.