org.springframework.jndi.support.SimpleJndiBeanFactory Java Examples

The following examples show how to use org.springframework.jndi.support.SimpleJndiBeanFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CommonAnnotationBeanPostProcessorTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void testResourceInjectionFromJndi() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
	SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	TestBean tb = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean", tb);
	TestBean tb2 = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean2", tb2);
	resourceFactory.setJndiTemplate(jndiTemplate);
	bpp.setResourceFactory(resourceFactory);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));

	ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
	assertTrue(bean.initCalled);
	assertTrue(bean.init2Called);
	assertSame(tb, bean.getTestBean());
	assertSame(tb2, bean.getTestBean2());
	bf.destroySingletons();
	assertTrue(bean.destroyCalled);
	assertTrue(bean.destroy2Called);
}
 
Example #2
Source File: CommonAnnotationBeanPostProcessorTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void testResourceInjectionFromJndi() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
	SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	TestBean tb = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean", tb);
	TestBean tb2 = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean2", tb2);
	resourceFactory.setJndiTemplate(jndiTemplate);
	bpp.setResourceFactory(resourceFactory);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));

	ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
	assertTrue(bean.initCalled);
	assertTrue(bean.init2Called);
	assertSame(tb, bean.getTestBean());
	assertSame(tb2, bean.getTestBean2());
	bf.destroySingletons();
	assertTrue(bean.destroyCalled);
	assertTrue(bean.destroy2Called);
}
 
Example #3
Source File: CommonAnnotationBeanPostProcessorTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testResourceInjectionFromJndi() {
	DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
	CommonAnnotationBeanPostProcessor bpp = new CommonAnnotationBeanPostProcessor();
	SimpleJndiBeanFactory resourceFactory = new SimpleJndiBeanFactory();
	ExpectedLookupTemplate jndiTemplate = new ExpectedLookupTemplate();
	TestBean tb = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean", tb);
	TestBean tb2 = new TestBean();
	jndiTemplate.addObject("java:comp/env/testBean2", tb2);
	resourceFactory.setJndiTemplate(jndiTemplate);
	bpp.setResourceFactory(resourceFactory);
	bf.addBeanPostProcessor(bpp);
	bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));

	ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
	assertTrue(bean.initCalled);
	assertTrue(bean.init2Called);
	assertSame(tb, bean.getTestBean());
	assertSame(tb2, bean.getTestBean2());
	bf.destroySingletons();
	assertTrue(bean.destroyCalled);
	assertTrue(bean.destroy2Called);
}
 
Example #4
Source File: SpringUtil.java    From learnjavabug with MIT License 5 votes vote down vote up
public static BeanFactory makeJNDITrigger(String jndiUrl) throws Exception {
  SimpleJndiBeanFactory bf = new SimpleJndiBeanFactory();
  bf.setShareableResources(jndiUrl);
  Reflections.setFieldValue(bf, "logger", new NoOpLog());
  Reflections.setFieldValue(bf.getJndiTemplate(), "logger", new NoOpLog());
  return bf;
}
 
Example #5
Source File: SpringUtil.java    From marshalsec with MIT License 5 votes vote down vote up
public static BeanFactory makeJNDITrigger ( String jndiUrl ) throws Exception {
    SimpleJndiBeanFactory bf = new SimpleJndiBeanFactory();
    bf.setShareableResources(jndiUrl);
    Reflections.setFieldValue(bf, "logger", new NoOpLog());
    Reflections.setFieldValue(bf.getJndiTemplate(), "logger", new NoOpLog());
    return bf;
}
 
Example #6
Source File: Jackson.java    From marshalsec with MIT License 4 votes vote down vote up
private static String makeSpringJndiBeanFactory ( String jndiUrl ) {
    return writeObject(SimpleJndiBeanFactory.class, Collections.singletonMap("shareableResources", writeArray(quoteString(jndiUrl))));
}