Search in sources :

Example 1 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project zeppelin by apache.

the class LensBootstrap method getLensJLineShellComponent.

public LensJLineShellComponent getLensJLineShellComponent() {
    GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition();
    rbd.setBeanClass(LensJLineShellComponent.class);
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
    bf.registerBeanDefinition(LensJLineShellComponent.class.getSimpleName(), rbd);
    return ctx.getBean(LensJLineShellComponent.class);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition)

Example 2 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class AbstractBeanFactoryBasedTargetSourceCreator method getInternalBeanFactoryForBean.

/**
	 * Return the internal BeanFactory to be used for the specified bean.
	 * @param beanName the name of the target bean
	 * @return the internal BeanFactory to be used
	 */
protected DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName) {
    synchronized (this.internalBeanFactories) {
        DefaultListableBeanFactory internalBeanFactory = this.internalBeanFactories.get(beanName);
        if (internalBeanFactory == null) {
            internalBeanFactory = buildInternalBeanFactory(this.beanFactory);
            this.internalBeanFactories.put(beanName, internalBeanFactory);
        }
        return internalBeanFactory;
    }
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory)

Example 3 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class TopLevelAopTagTests method testParse.

@Test
public void testParse() throws Exception {
    DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
    reader.loadBeanDefinitions(CONTEXT);
    assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 4 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testAutowireBeanByNameWithNoDependencyCheck.

@Test
public void testAutowireBeanByNameWithNoDependencyCheck() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
    lbf.registerBeanDefinition("spous", bd);
    DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
    assertNull(bean.getSpouse());
}
Also used : DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ConstructorDependenciesBean(org.springframework.beans.factory.xml.ConstructorDependenciesBean) DependenciesBean(org.springframework.tests.sample.beans.DependenciesBean) Test(org.junit.Test)

Example 5 with DefaultListableBeanFactory

use of org.springframework.beans.factory.support.DefaultListableBeanFactory in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching.

@Test
public void testPrototypeFactoryBeanIgnoredByNonEagerTypeMatching() {
    DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
    Properties p = new Properties();
    p.setProperty("x1.(class)", DummyFactory.class.getName());
    // Reset static state
    DummyFactory.reset();
    p.setProperty("x1.(singleton)", "false");
    p.setProperty("x1.singleton", "false");
    (new PropertiesBeanDefinitionReader(lbf)).registerBeanDefinitions(p);
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
    String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
    assertEquals(0, beanNames.length);
    beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
    assertEquals(0, beanNames.length);
    assertFalse(lbf.containsSingleton("x1"));
    assertTrue(lbf.containsBean("x1"));
    assertTrue(lbf.containsBean("&x1"));
    assertFalse(lbf.isSingleton("x1"));
    assertFalse(lbf.isSingleton("&x1"));
    assertTrue(lbf.isPrototype("x1"));
    assertTrue(lbf.isPrototype("&x1"));
    assertTrue(lbf.isTypeMatch("x1", TestBean.class));
    assertFalse(lbf.isTypeMatch("&x1", TestBean.class));
    assertTrue(lbf.isTypeMatch("&x1", DummyFactory.class));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClass(DummyFactory.class)));
    assertTrue(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, Object.class)));
    assertFalse(lbf.isTypeMatch("&x1", ResolvableType.forClassWithGenerics(FactoryBean.class, String.class)));
    assertEquals(TestBean.class, lbf.getType("x1"));
    assertEquals(DummyFactory.class, lbf.getType("&x1"));
    assertTrue("prototype not instantiated", !DummyFactory.wasPrototypeCreated());
}
Also used : DummyFactory(org.springframework.tests.sample.beans.factory.DummyFactory) ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) PropertiesBeanDefinitionReader(org.springframework.beans.factory.support.PropertiesBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)801 Test (org.junit.jupiter.api.Test)354 Test (org.junit.Test)298 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)229 TestBean (org.springframework.beans.testfixture.beans.TestBean)124 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)100 ITestBean (org.springframework.tests.sample.beans.ITestBean)94 TestBean (org.springframework.tests.sample.beans.TestBean)94 DerivedTestBean (org.springframework.tests.sample.beans.DerivedTestBean)91 ClassPathResource (org.springframework.core.io.ClassPathResource)86 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)73 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)69 ResourceTestBean (org.springframework.tests.sample.beans.ResourceTestBean)50 BeanCreationException (org.springframework.beans.factory.BeanCreationException)41 DerivedTestBean (org.springframework.beans.testfixture.beans.DerivedTestBean)38 Properties (java.util.Properties)35 HashMap (java.util.HashMap)30 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)29 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)28 BeforeEach (org.junit.jupiter.api.BeforeEach)27