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);
}
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);
}
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;
}
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;
}
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));
}
Aggregations