Search in sources :

Example 76 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireByType.

@Test
public void testAutowireByType() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByTypeTests.xml");
    try {
        context.refresh();
        fail("expected exception due to multiple matches for byType autowiring");
    } catch (UnsatisfiedDependencyException ex) {
    // expected
    }
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) UnsatisfiedDependencyException(org.springframework.beans.factory.UnsatisfiedDependencyException) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 77 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testDefaultInitAndDestroyMethodsNotDefined.

@Test
public void testDefaultInitAndDestroyMethodsNotDefined() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertFalse("bean should not have been initialized", bean.isInitialized());
    context.close();
    assertFalse("bean should not have been destroyed", bean.isDestroyed());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 78 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class ComponentScanParserBeanDefinitionDefaultsTests method testAutowireByName.

@Test
public void testAutowireByName() {
    GenericApplicationContext context = new GenericApplicationContext();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
    reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByNameTests.xml");
    context.refresh();
    DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
    assertNull("constructor dependency should not have been autowired", bean.getConstructorDependency());
    assertNull("propertyDependency1 should not have been autowired", bean.getPropertyDependency1());
    assertNotNull("propertyDependency2 should have been autowired", bean.getPropertyDependency2());
    assertEquals("pd2", bean.getPropertyDependency2().getName());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) Test(org.junit.Test)

Example 79 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class ConfigurationClassProcessingTests method configWithSetWithProviderImplementation.

// SPR-11830
@Test
public void configWithSetWithProviderImplementation() {
    GenericApplicationContext ac = new GenericApplicationContext();
    AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
    ac.registerBeanDefinition("config", new RootBeanDefinition(ConfigWithSetWithProviderImplementation.class));
    ac.refresh();
    assertSame(ac.getBean("customName"), ConfigWithSetWithProviderImplementation.set);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 80 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project spring-framework by spring-projects.

the class AutowiredConfigurationTests method testAutowiredSingleConstructorSupported.

@Test
public void testAutowiredSingleConstructorSupported() {
    DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(factory).loadBeanDefinitions(new ClassPathResource("annotation-config.xml", AutowiredConstructorConfig.class));
    GenericApplicationContext ctx = new GenericApplicationContext(factory);
    ctx.registerBeanDefinition("config1", new RootBeanDefinition(AutowiredConstructorConfig.class));
    ctx.registerBeanDefinition("config2", new RootBeanDefinition(ColorConfig.class));
    ctx.refresh();
    assertSame(ctx.getBean(AutowiredConstructorConfig.class).colour, ctx.getBean(Colour.class));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) ClassPathResource(org.springframework.core.io.ClassPathResource) Colour(org.springframework.tests.sample.beans.Colour) Test(org.junit.Test)

Aggregations

GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)245 Test (org.junit.Test)190 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)80 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)50 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)38 BeanCreationException (org.springframework.beans.factory.BeanCreationException)26 ClassPathResource (org.springframework.core.io.ClassPathResource)19 TestBean (org.springframework.tests.sample.beans.TestBean)17 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)15 DefaultAdvisorAutoProxyCreator (org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)12 MBeanExporter (org.springframework.jmx.export.MBeanExporter)11 BeansException (org.springframework.beans.BeansException)8 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)8 HashMap (java.util.HashMap)7 UnsatisfiedDependencyException (org.springframework.beans.factory.UnsatisfiedDependencyException)7 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 Before (org.junit.Before)6 Properties (java.util.Properties)5 EntityManager (javax.persistence.EntityManager)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5