Example usage for org.springframework.beans.factory.support DefaultListableBeanFactory freezeConfiguration

List of usage examples for org.springframework.beans.factory.support DefaultListableBeanFactory freezeConfiguration

Introduction

In this page you can find the example usage for org.springframework.beans.factory.support DefaultListableBeanFactory freezeConfiguration.

Prototype

@Override
    public void freezeConfiguration() 

Source Link

Usage

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

@Test
public void testGetTypeWorksAfterParentChildMerging() {
    RootBeanDefinition parentDefinition = new RootBeanDefinition(TestBean.class);
    ChildBeanDefinition childDefinition = new ChildBeanDefinition("parent", DerivedTestBean.class, null, null);

    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    factory.registerBeanDefinition("parent", parentDefinition);
    factory.registerBeanDefinition("child", childDefinition);
    factory.freezeConfiguration();

    assertEquals(TestBean.class, factory.getType("parent"));
    assertEquals(DerivedTestBean.class, factory.getType("child"));
}

From source file:org.springframework.beans.factory.DefaultListableBeanFactoryTests.java

/**
 * Test that by-type bean lookup caching is working effectively by searching for a
 * bean of type B 10K times within a container having 1K additional beans of type A.
 * Prior to by-type caching, each bean lookup would traverse the entire container
 * (all 1001 beans), performing expensive assignability checks, etc. Now these
 * operations are necessary only once, providing a dramatic performance improvement.
 * On load-free modern hardware (e.g. an 8-core MPB), this method should complete well
 * under the 1000 ms timeout, usually ~= 300ms. With caching removed and on the same
 * hardware the method will take ~13000 ms. See SPR-6870.
 *///from w w  w.j  a va2s. c  om
@Test(timeout = 1000)
public void testByTypeLookupIsFastEnough() {
    Assume.group(TestGroup.PERFORMANCE);
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();

    for (int i = 0; i < 1000; i++) {
        bf.registerBeanDefinition("a" + i, new RootBeanDefinition(A.class));
    }
    bf.registerBeanDefinition("b", new RootBeanDefinition(B.class));

    bf.freezeConfiguration();

    for (int i = 0; i < 10000; i++) {
        bf.getBean(B.class);
    }
}