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


Java DefaultListableBeanFactory.destroySingletons方法代码示例

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


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

示例1: testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testMethodInjectionWithMapAndMultipleMatchesButOnlyOneAutowireCandidate() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class));
	bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class));
	RootBeanDefinition rbd2 = new RootBeanDefinition(TestBean.class);
	rbd2.setAutowireCandidate(false);
	bf.registerBeanDefinition("testBean2", rbd2);

	MapMethodInjectionBean bean = (MapMethodInjectionBean) bf.getBean("annotatedBean");
	TestBean tb = (TestBean) bf.getBean("testBean1");
	assertEquals(1, bean.getTestBeanMap().size());
	assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
	assertTrue(bean.getTestBeanMap().values().contains(tb));
	assertSame(tb, bean.getTestBean());
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:InjectAnnotationBeanPostProcessorTests.java

示例2: testBeanAutowiredWithFactoryBean

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * Verifies that a dependency on a {@link org.springframework.beans.factory.FactoryBean} can be autowired via
 * {@link org.springframework.beans.factory.annotation.Autowired @Inject}, specifically addressing the JIRA issue
 * raised in <a
 * href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
 * target="_blank">SPR-4040</a>.
 */
@Test
public void testBeanAutowiredWithFactoryBean() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("factoryBeanDependentBean", new RootBeanDefinition(FactoryBeanDependentBean.class));
	bf.registerSingleton("stringFactoryBean", new StringFactoryBean());

	final StringFactoryBean factoryBean = (StringFactoryBean) bf.getBean("&stringFactoryBean");
	final FactoryBeanDependentBean bean = (FactoryBeanDependentBean) bf.getBean("factoryBeanDependentBean");

	assertNotNull("The singleton StringFactoryBean should have been registered.", factoryBean);
	assertNotNull("The factoryBeanDependentBean should have been registered.", bean);
	assertEquals("The FactoryBeanDependentBean should have been autowired 'by type' with the StringFactoryBean.",
			factoryBean, bean.getFactoryBean());

	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:InjectAnnotationBeanPostProcessorTests.java

示例3: testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setAutowiredAnnotationType(MyAutowired.class);
	bpp.setRequiredParameterName("optional");
	bpp.setRequiredParameterValue(false);
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("customBean", new RootBeanDefinition(
			CustomAnnotationRequiredFieldResourceInjectionBean.class));
	TestBean tb1 = new TestBean();
	bf.registerSingleton("testBean1", tb1);
	TestBean tb2 = new TestBean();
	bf.registerSingleton("testBean2", tb2);

	try {
		bf.getBean("customBean");
		fail("expected BeanCreationException; multiple beans of dependency type available");
	}
	catch (BeanCreationException e) {
		// expected
	}
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例4: testCustomAnnotationRequiredMethodResourceInjection

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testCustomAnnotationRequiredMethodResourceInjection() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setAutowiredAnnotationType(MyAutowired.class);
	bpp.setRequiredParameterName("optional");
	bpp.setRequiredParameterValue(false);
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("customBean", new RootBeanDefinition(
			CustomAnnotationRequiredMethodResourceInjectionBean.class));
	TestBean tb = new TestBean();
	bf.registerSingleton("testBean", tb);

	CustomAnnotationRequiredMethodResourceInjectionBean bean = (CustomAnnotationRequiredMethodResourceInjectionBean) bf.getBean("customBean");
	assertSame(tb, bean.getTestBean());
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例5: initMethod

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void initMethod() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
			new ClassPathResource("NestedBeansElementAttributeRecursionTests-init-destroy-context.xml", this.getClass()));

	InitDestroyBean beanA = bf.getBean("beanA", InitDestroyBean.class);
	InitDestroyBean beanB = bf.getBean("beanB", InitDestroyBean.class);
	InitDestroyBean beanC = bf.getBean("beanC", InitDestroyBean.class);
	InitDestroyBean beanD = bf.getBean("beanD", InitDestroyBean.class);

	assertThat(beanA.initMethod1Called, is(true));
	assertThat(beanB.initMethod2Called, is(true));
	assertThat(beanC.initMethod3Called, is(true));
	assertThat(beanD.initMethod2Called, is(true));

	bf.destroySingletons();

	assertThat(beanA.destroyMethod1Called, is(true));
	assertThat(beanB.destroyMethod2Called, is(true));
	assertThat(beanC.destroyMethod3Called, is(true));
	assertThat(beanD.destroyMethod2Called, is(true));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:NestedBeansElementAttributeRecursionTests.java

示例6: testConstructorResourceInjectionWithMultipleCandidatesAsOrderedCollection

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testConstructorResourceInjectionWithMultipleCandidatesAsOrderedCollection() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(
			ConstructorsCollectionResourceInjectionBean.class));
	TestBean tb = new TestBean();
	bf.registerSingleton("testBean", tb);
	FixedOrder2NestedTestBean ntb1 = new FixedOrder2NestedTestBean();
	bf.registerSingleton("nestedTestBean1", ntb1);
	FixedOrder1NestedTestBean ntb2 = new FixedOrder1NestedTestBean();
	bf.registerSingleton("nestedTestBean2", ntb2);

	ConstructorsCollectionResourceInjectionBean bean = (ConstructorsCollectionResourceInjectionBean) bf.getBean("annotatedBean");
	assertNull(bean.getTestBean3());
	assertSame(tb, bean.getTestBean4());
	assertEquals(2, bean.getNestedTestBeans().size());
	assertSame(ntb2, bean.getNestedTestBeans().get(0));
	assertSame(ntb1, bean.getNestedTestBeans().get(1));
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例7: testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setAutowiredAnnotationType(MyAutowired.class);
	bpp.setRequiredParameterName("optional");
	bpp.setRequiredParameterValue(false);
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("customBean", new RootBeanDefinition(
			CustomAnnotationOptionalFieldResourceInjectionBean.class));
	TestBean tb1 = new TestBean();
	bf.registerSingleton("testBean1", tb1);
	TestBean tb2 = new TestBean();
	bf.registerSingleton("testBean2", tb2);

	try {
		bf.getBean("customBean");
		fail("expected BeanCreationException; multiple beans of dependency type available");
	}
	catch (BeanCreationException e) {
		// expected
	}
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例8: testExtendedResourceInjectionWithOverriding

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testExtendedResourceInjectionWithOverriding() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.registerResolvableDependency(BeanFactory.class, bf);
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	RootBeanDefinition annotatedBd = new RootBeanDefinition(TypedExtendedResourceInjectionBean.class);
	TestBean tb2 = new TestBean();
	annotatedBd.getPropertyValues().add("testBean2", tb2);
	bf.registerBeanDefinition("annotatedBean", annotatedBd);
	TestBean tb = new TestBean();
	bf.registerSingleton("testBean", tb);
	NestedTestBean ntb = new NestedTestBean();
	bf.registerSingleton("nestedTestBean", ntb);

	TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
	assertSame(tb, bean.getTestBean());
	assertSame(tb2, bean.getTestBean2());
	assertSame(tb, bean.getTestBean3());
	assertSame(tb, bean.getTestBean4());
	assertSame(ntb, bean.getNestedTestBean());
	assertSame(bf, bean.getBeanFactory());
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例9: testCustomAnnotationRequiredMethodResourceInjectionFailsWhenMultipleDependenciesFound

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testCustomAnnotationRequiredMethodResourceInjectionFailsWhenMultipleDependenciesFound() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setAutowiredAnnotationType(MyAutowired.class);
	bpp.setRequiredParameterName("optional");
	bpp.setRequiredParameterValue(false);
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("customBean", new RootBeanDefinition(
			CustomAnnotationRequiredMethodResourceInjectionBean.class));
	TestBean tb1 = new TestBean();
	bf.registerSingleton("testBean1", tb1);
	TestBean tb2 = new TestBean();
	bf.registerSingleton("testBean2", tb2);

	try {
		bf.getBean("customBean");
		fail("expected BeanCreationException; multiple beans of dependency type available");
	}
	catch (BeanCreationException e) {
		// expected
	}
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:26,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例10: testMethodInjectionWithMapAndMultipleMatches

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testMethodInjectionWithMapAndMultipleMatches() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(MapMethodInjectionBean.class));
	bf.registerBeanDefinition("testBean1", new RootBeanDefinition(TestBean.class));
	bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class));

	try {
		bf.getBean("annotatedBean");
		fail("should have failed, more than one bean of type");
	}
	catch (BeanCreationException e) {
		// expected
	}
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:InjectAnnotationBeanPostProcessorTests.java

示例11: testBeanAutowiredWithFactoryBean

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * Verifies that a dependency on a {@link FactoryBean} can be autowired via
 * {@link Autowired @Autowired}, specifically addressing the JIRA issue
 * raised in <a
 * href="http://opensource.atlassian.com/projects/spring/browse/SPR-4040"
 * target="_blank">SPR-4040</a>.
 */
@Test
public void testBeanAutowiredWithFactoryBean() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("factoryBeanDependentBean", new RootBeanDefinition(FactoryBeanDependentBean.class));
	bf.registerSingleton("stringFactoryBean", new StringFactoryBean());

	final StringFactoryBean factoryBean = (StringFactoryBean) bf.getBean("&stringFactoryBean");
	final FactoryBeanDependentBean bean = (FactoryBeanDependentBean) bf.getBean("factoryBeanDependentBean");

	assertNotNull("The singleton StringFactoryBean should have been registered.", factoryBean);
	assertNotNull("The factoryBeanDependentBean should have been registered.", bean);
	assertEquals("The FactoryBeanDependentBean should have been autowired 'by type' with the StringFactoryBean.",
			factoryBean, bean.getFactoryBean());

	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例12: destroy

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
/**
 * Destroys the internal BeanFactory on shutdown of the TargetSourceCreator.
 * @see #getInternalBeanFactoryForBean
 */
@Override
public void destroy() {
	synchronized (this.internalBeanFactories) {
		for (DefaultListableBeanFactory bf : this.internalBeanFactories.values()) {
			bf.destroySingletons();
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:13,代码来源:AbstractBeanFactoryBasedTargetSourceCreator.java

示例13: testOrderedCollectionResourceInjection

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testOrderedCollectionResourceInjection() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	RootBeanDefinition rbd = new RootBeanDefinition(OptionalCollectionResourceInjectionBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	bf.registerBeanDefinition("annotatedBean", rbd);
	TestBean tb = new TestBean();
	bf.registerSingleton("testBean", tb);
	IndexedTestBean itb = new IndexedTestBean();
	bf.registerSingleton("indexedTestBean", itb);
	OrderedNestedTestBean ntb1 = new OrderedNestedTestBean();
	ntb1.setOrder(2);
	bf.registerSingleton("nestedTestBean1", ntb1);
	OrderedNestedTestBean ntb2 = new OrderedNestedTestBean();
	ntb2.setOrder(1);
	bf.registerSingleton("nestedTestBean2", ntb2);

	// Two calls to verify that caching doesn't break re-creation.
	OptionalCollectionResourceInjectionBean bean = (OptionalCollectionResourceInjectionBean) bf.getBean("annotatedBean");
	bean = (OptionalCollectionResourceInjectionBean) bf.getBean("annotatedBean");
	assertSame(tb, bean.getTestBean());
	assertSame(tb, bean.getTestBean2());
	assertSame(tb, bean.getTestBean3());
	assertSame(tb, bean.getTestBean4());
	assertSame(itb, bean.getIndexedTestBean());
	assertEquals(2, bean.getNestedTestBeans().size());
	assertSame(ntb2, bean.getNestedTestBeans().get(0));
	assertSame(ntb1, bean.getNestedTestBeans().get(1));
	assertEquals(2, bean.nestedTestBeansSetter.size());
	assertSame(ntb2, bean.nestedTestBeansSetter.get(0));
	assertSame(ntb1, bean.nestedTestBeansSetter.get(1));
	assertEquals(2, bean.nestedTestBeansField.size());
	assertSame(ntb2, bean.nestedTestBeansField.get(0));
	assertSame(ntb1, bean.nestedTestBeansField.get(1));
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:41,代码来源:AutowiredAnnotationBeanPostProcessorTests.java

示例14: testOptionalMethodInjectionWithBeanNotAvailable

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testOptionalMethodInjectionWithBeanNotAvailable() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
	bpp.setBeanFactory(bf);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class));

	OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
	assertFalse(bean.getTestBean().isPresent());
	bf.destroySingletons();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:InjectAnnotationBeanPostProcessorTests.java

示例15: testJsr250AnnotationsWithShadowedMethods

import org.springframework.beans.factory.support.DefaultListableBeanFactory; //导入方法依赖的package包/类
@Test
public void testJsr250AnnotationsWithShadowedMethods() {
	final Class<?> beanClass = CustomAnnotatedInitDestroyWithShadowedMethodsBean.class;
	final DefaultListableBeanFactory beanFactory = createBeanFactoryAndRegisterBean(beanClass, "customInit",
			"customDestroy");
	final CustomAnnotatedInitDestroyWithShadowedMethodsBean bean = (CustomAnnotatedInitDestroyWithShadowedMethodsBean) beanFactory.getBean(LIFECYCLE_TEST_BEAN);
	assertMethodOrdering(beanClass, "init-methods",
			Arrays.asList("@PostConstruct.afterPropertiesSet", "customInit"), bean.initMethods);
	beanFactory.destroySingletons();
	assertMethodOrdering(beanClass, "destroy-methods", Arrays.asList("@PreDestroy.destroy", "customDestroy"),
			bean.destroyMethods);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:Spr3775InitDestroyLifecycleTests.java


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