use of org.springframework.beans.factory.support.StaticListableBeanFactory in project spring-framework by spring-projects.
the class BeanFactoryUtilsTests method testFindsBeansOfTypeWithStaticFactory.
@Test
public void testFindsBeansOfTypeWithStaticFactory() {
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
TestBean t1 = new TestBean();
TestBean t2 = new TestBean();
DummyFactory t3 = new DummyFactory();
DummyFactory t4 = new DummyFactory();
t4.setSingleton(false);
lbf.addBean("t1", t1);
lbf.addBean("t2", t2);
lbf.addBean("t3", t3);
lbf.addBean("t4", t4);
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
assertEquals(4, beans.size());
assertEquals(t1, beans.get("t1"));
assertEquals(t2, beans.get("t2"));
assertEquals(t3.getObject(), beans.get("t3"));
assertTrue(beans.get("t4") instanceof TestBean);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
assertEquals(2, beans.size());
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
assertEquals(2, beans.size());
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
}
use of org.springframework.beans.factory.support.StaticListableBeanFactory in project spring-framework by spring-projects.
the class ClassPathBeanDefinitionScannerTests method testBeanAutowiredWithAnnotationConfigEnabled.
@Test
public void testBeanAutowiredWithAnnotationConfigEnabled() {
GenericApplicationContext context = new GenericApplicationContext();
context.registerBeanDefinition("myBf", new RootBeanDefinition(StaticListableBeanFactory.class));
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
context.refresh();
FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
MessageSource ms = (MessageSource) context.getBean("messageSource");
assertTrue(fooService.isInitCalled());
assertEquals("bar", fooService.foo(123));
assertEquals("bar", fooService.lookupFoo(123));
assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
assertEquals(2, fooService.listableBeanFactory.size());
assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
assertSame(myBf, fooService.listableBeanFactory.get(1));
assertSame(context, fooService.resourceLoader);
assertSame(context, fooService.resourcePatternResolver);
assertSame(context, fooService.eventPublisher);
assertSame(ms, fooService.messageSource);
assertSame(context, fooService.context);
assertEquals(1, fooService.configurableContext.length);
assertSame(context, fooService.configurableContext[0]);
assertSame(context, fooService.genericContext);
}
use of org.springframework.beans.factory.support.StaticListableBeanFactory in project spring-framework by spring-projects.
the class JmsListenerContainerFactoryIntegrationTests method initializeFactory.
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
factory.setBeanFactory(new StaticListableBeanFactory());
factory.afterPropertiesSet();
}
use of org.springframework.beans.factory.support.StaticListableBeanFactory in project spring-framework by spring-projects.
the class MethodJmsListenerEndpointTests method initializeFactory.
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
factory.setBeanFactory(new StaticListableBeanFactory());
factory.afterPropertiesSet();
}
use of org.springframework.beans.factory.support.StaticListableBeanFactory in project spring-framework by spring-projects.
the class MessagingMessageListenerAdapterTests method initializeFactory.
private void initializeFactory(DefaultMessageHandlerMethodFactory factory) {
factory.setBeanFactory(new StaticListableBeanFactory());
factory.afterPropertiesSet();
}
Aggregations