当前位置: 首页>>代码示例>>Java>>正文


Java DefaultListableBeanFactory.freezeConfiguration方法代码示例

本文整理汇总了Java中org.springframework.beans.factory.support.DefaultListableBeanFactory.freezeConfiguration方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultListableBeanFactory.freezeConfiguration方法的具体用法?Java DefaultListableBeanFactory.freezeConfiguration怎么用?Java DefaultListableBeanFactory.freezeConfiguration使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.beans.factory.support.DefaultListableBeanFactory的用法示例。


在下文中一共展示了DefaultListableBeanFactory.freezeConfiguration方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: initBeanFactory

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * Creates a new {@link BeanFactory}, populates it with a {@link BeanDefinition} for
 * each of the given {@link Configuration} <var>configClasses</var>, and then
 * post-processes the factory using JavaConfig's {@link ConfigurationClassPostProcessor}.
 * When complete, the factory is ready to service requests for any {@link Bean} methods
 * declared by <var>configClasses</var>.
 */
private ListableBeanFactory initBeanFactory(Class<?>... configClasses) {
	DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
	for (Class<?> configClass : configClasses) {
		String configBeanName = configClass.getName();
		factory.registerBeanDefinition(configBeanName, new RootBeanDefinition(configClass));
	}
	ConfigurationClassPostProcessor ccpp = new ConfigurationClassPostProcessor();
	ccpp.postProcessBeanDefinitionRegistry(factory);
	ccpp.postProcessBeanFactory(factory);
	RequiredAnnotationBeanPostProcessor rapp = new RequiredAnnotationBeanPostProcessor();
	rapp.setBeanFactory(factory);
	factory.addBeanPostProcessor(rapp);
	factory.freezeConfiguration();
	return factory;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ConfigurationClassProcessingTests.java

示例2: testByTypeLookupIsFastEnough

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * 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.
 */
@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);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:DefaultListableBeanFactoryTests.java

示例3: testGetTypeWorksAfterParentChildMerging

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@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"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:DefaultListableBeanFactoryTests.java


注:本文中的org.springframework.beans.factory.support.DefaultListableBeanFactory.freezeConfiguration方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。