Search in sources :

Example 1 with StaticListableBeanFactory

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"));
}
Also used : DummyFactory(org.springframework.tests.sample.beans.factory.DummyFactory) StaticListableBeanFactory(org.springframework.beans.factory.support.StaticListableBeanFactory) IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) Test(org.junit.Test)

Example 2 with StaticListableBeanFactory

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);
}
Also used : FooServiceImpl(example.scannable.FooServiceImpl) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StaticListableBeanFactory(org.springframework.beans.factory.support.StaticListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) MessageSource(org.springframework.context.MessageSource) Test(org.junit.Test)

Example 3 with StaticListableBeanFactory

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();
}
Also used : StaticListableBeanFactory(org.springframework.beans.factory.support.StaticListableBeanFactory)

Example 4 with StaticListableBeanFactory

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();
}
Also used : StaticListableBeanFactory(org.springframework.beans.factory.support.StaticListableBeanFactory)

Example 5 with StaticListableBeanFactory

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();
}
Also used : StaticListableBeanFactory(org.springframework.beans.factory.support.StaticListableBeanFactory)

Aggregations

StaticListableBeanFactory (org.springframework.beans.factory.support.StaticListableBeanFactory)11 Test (org.junit.Test)4 ITestBean (org.springframework.tests.sample.beans.ITestBean)2 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)2 TestBean (org.springframework.tests.sample.beans.TestBean)2 FooServiceImpl (example.scannable.FooServiceImpl)1 Connection (java.sql.Connection)1 HashMap (java.util.HashMap)1 DataSource (javax.sql.DataSource)1 Before (org.junit.Before)1 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)1 MessageSource (org.springframework.context.MessageSource)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 BeanFactoryDataSourceLookup (org.springframework.jdbc.datasource.lookup.BeanFactoryDataSourceLookup)1 IsolationLevelDataSourceRouter (org.springframework.jdbc.datasource.lookup.IsolationLevelDataSourceRouter)1 DummyFactory (org.springframework.tests.sample.beans.factory.DummyFactory)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 JtaTransactionManager (org.springframework.transaction.jta.JtaTransactionManager)1 JtaTransactionObject (org.springframework.transaction.jta.JtaTransactionObject)1 TransactionCallbackWithoutResult (org.springframework.transaction.support.TransactionCallbackWithoutResult)1