Search in sources :

Example 51 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project camel by apache.

the class CamelContextFactoryBeanTest method testGenericApplicationContextUsingNamespaces.

public void testGenericApplicationContextUsingNamespaces() throws Exception {
    applicationContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) applicationContext);
    xmlReader.loadBeanDefinitions(new ClassPathResource("org/apache/camel/spring/camelContextFactoryBean.xml"));
    // lets refresh to inject the applicationContext into beans
    applicationContext.refresh();
    CamelContext context = applicationContext.getBean("camel3", CamelContext.class);
    assertValidContext(context);
}
Also used : CamelContext(org.apache.camel.CamelContext) SpringCamelContext(org.apache.camel.spring.SpringCamelContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 52 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext 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 53 with GenericApplicationContext

use of org.springframework.context.support.GenericApplicationContext in project cucumber-jvm by cucumber.

the class CucumberTestContextManager method createFallbackContext.

@SuppressWarnings("resource")
private ConfigurableListableBeanFactory createFallbackContext() {
    ConfigurableApplicationContext applicationContext;
    if (getClass().getClassLoader().getResource("cucumber.xml") != null) {
        applicationContext = new ClassPathXmlApplicationContext("cucumber.xml");
    } else {
        applicationContext = new GenericApplicationContext();
    }
    applicationContext.registerShutdownHook();
    ConfigurableListableBeanFactory beanFactory = applicationContext.getBeanFactory();
    beanFactory.registerScope(GlueCodeScope.NAME, new GlueCodeScope());
    for (Class<?> stepClass : stepClasses) {
        registerStepClassBeanDefinition(beanFactory, stepClass);
    }
    return beanFactory;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory)

Example 54 with GenericApplicationContext

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

the class PersistenceInjectionTests method testPublicExtendedPersistenceContextSetterWithSerialization.

@Test
public void testPublicExtendedPersistenceContextSetterWithSerialization() throws Exception {
    DummyInvocationHandler ih = new DummyInvocationHandler();
    Object mockEm = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { EntityManager.class }, ih);
    given(mockEmf.createEntityManager()).willReturn((EntityManager) mockEm);
    GenericApplicationContext gac = new GenericApplicationContext();
    SimpleMapScope myScope = new SimpleMapScope();
    gac.getDefaultListableBeanFactory().registerScope("myScope", myScope);
    gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
    gac.registerBeanDefinition("annotationProcessor", new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class);
    bd.setScope("myScope");
    gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(), bd);
    gac.refresh();
    DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(DefaultPublicPersistenceContextSetter.class.getName());
    assertNotNull(bean.em);
    assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
    SimpleMapScope serialized = (SimpleMapScope) SerializationTestUtils.serializeAndDeserialize(myScope);
    serialized.close();
    assertTrue(DummyInvocationHandler.closed);
    DummyInvocationHandler.closed = false;
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) SimpleMapScope(org.springframework.tests.context.SimpleMapScope) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Test(org.junit.Test)

Example 55 with GenericApplicationContext

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

the class PersistenceInjectionTests method testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization.

@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testPublicExtendedPersistenceContextSetterWithEntityManagerInfoAndSerialization() throws Exception {
    EntityManager mockEm = mock(EntityManager.class, withSettings().serializable());
    given(mockEm.isOpen()).willReturn(true);
    EntityManagerFactoryWithInfo mockEmf = mock(EntityManagerFactoryWithInfo.class);
    given(mockEmf.getNativeEntityManagerFactory()).willReturn(mockEmf);
    given(mockEmf.getJpaDialect()).willReturn(new DefaultJpaDialect());
    given(mockEmf.getEntityManagerInterface()).willReturn((Class) EntityManager.class);
    given(mockEmf.getBeanClassLoader()).willReturn(getClass().getClassLoader());
    given(mockEmf.createEntityManager()).willReturn(mockEm);
    GenericApplicationContext gac = new GenericApplicationContext();
    gac.getDefaultListableBeanFactory().registerSingleton("entityManagerFactory", mockEmf);
    gac.registerBeanDefinition("annotationProcessor", new RootBeanDefinition(PersistenceAnnotationBeanPostProcessor.class));
    gac.registerBeanDefinition(DefaultPublicPersistenceContextSetter.class.getName(), new RootBeanDefinition(DefaultPublicPersistenceContextSetter.class));
    gac.refresh();
    DefaultPublicPersistenceContextSetter bean = (DefaultPublicPersistenceContextSetter) gac.getBean(DefaultPublicPersistenceContextSetter.class.getName());
    assertNotNull(bean.em);
    assertNotNull(SerializationTestUtils.serializeAndDeserialize(bean.em));
}
Also used : EntityManager(javax.persistence.EntityManager) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) DefaultJpaDialect(org.springframework.orm.jpa.DefaultJpaDialect) 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