Spring Framework StaticApplicationContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework StaticApplicationContext class.

This code example shows how to use the following methods:getBean, registerBeanDefinition
 * @author Mark Fisher 
 */ 
public class GroovyClassLoadingTests extends TestCase {
 
	public void testClassLoading() throws Exception {
		StaticApplicationContext context = new StaticApplicationContext();
 
		GroovyClassLoader gcl = new GroovyClassLoader();
		Class<?> class1 = gcl.parseClass("class TestBean { def myMethod() { \"foo\" } }");
		Class<?> class2 = gcl.parseClass("class TestBean { def myMethod() { \"bar\" } }");
 
		context.registerBeanDefinition("testBean", new RootBeanDefinition(class1));
		Object testBean1 = context.getBean("testBean");
		Method method1 = class1.getDeclaredMethod("myMethod", new Class<?>[0]);
		Object result1 = ReflectionUtils.invokeMethod(method1, testBean1);
		assertEquals("foo", (String) result1);
 
		// ### uncommenting the next line causes the test to pass for Spring > 2.0.2 ### 
		//context.removeBeanDefinition("testBean"); 
 

7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:close, getAutowireCapableBeanFactory, refresh
 
public class SpringBeanJobTests { 
 
	@Test
	public void testBeanName() throws Exception {
		StaticApplicationContext context = new StaticApplicationContext();
		JobSupport configuration = new JobSupport();
		context.getAutowireCapableBeanFactory().initializeBean(configuration,
				"bean"); 
		context.refresh();
		assertNotNull(configuration.getName());
		configuration.setBeanName("foo");
		context.getAutowireCapableBeanFactory().initializeBean(configuration,
				"bean"); 
		assertEquals("bean", configuration.getName());
		context.close();
	} 
 
	@Test
	public void testBeanNameWithBeanDefinition() throws Exception {
		GenericApplicationContext context = new GenericApplicationContext();
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerSingleton, refresh
 
public class MockWebServiceClientTest { 
 
    @Test
    public void createServerApplicationContext() throws Exception {
        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.registerSingleton("messageDispatcher", SoapMessageDispatcher.class);
        applicationContext.registerSingleton("messageFactory", SaajSoapMessageFactory.class);
        applicationContext.refresh();
 
        MockWebServiceClient client = MockWebServiceClient.createClient(applicationContext);
        assertNotNull(client);
    } 
     
    @Test
    public void createServerApplicationContextDefaults() throws Exception {
        StaticApplicationContext applicationContext = new StaticApplicationContext();
        applicationContext.refresh();
 
        MockWebServiceClient client = MockWebServiceClient.createClient(applicationContext);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getStaticMessageSource, refresh
 
	public void testResourceBundleRead() throws Exception {
		MockExternalContext externalContext = (MockExternalContext) requestContext.getExternalContext();
		externalContext.setLocale(Locale.ENGLISH);
 
		StaticApplicationContext applicationContext = new StaticApplicationContext();
		StaticMessageSource messageSource = applicationContext.getStaticMessageSource();
		messageSource.addMessage("myCode", externalContext.getLocale(), "myCode message");
		messageSource.addMessage("myCode.myCode", externalContext.getLocale(), "myCode myCode message");
		applicationContext.refresh();
 
		Flow flow = (Flow) requestContext.getActiveFlow();
		flow.setApplicationContext(applicationContext);
 
		String expressionString = "#{resourceBundle.myCode}";
		Expression exp = parser.parseExpression(expressionString, new FluentParserContext().template());
		assertEquals("myCode message", exp.getValue(requestContext));
 
		expressionString = "#{resourceBundle['myCode']}";
		exp = parser.parseExpression(expressionString, new FluentParserContext().template());
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerPrototype
	} 
 
	private void prepareTargetSource(CommonsPoolTargetSource targetSource) { 
		String beanName = "target"; 
 
		StaticApplicationContext applicationContext = new StaticApplicationContext(); 
		applicationContext.registerPrototype(beanName, SerializablePerson.class); 
 
		targetSource.setTargetBeanName(beanName); 
		targetSource.setBeanFactory(applicationContext); 
	} 
 
} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerSingleton
 
    @Test
    public void lookupByTypeSearchInParentAlso() 
    { 
        createSpringRegistryWithParentContext(); 
        applicationContext.registerSingleton(BEAN_KEY, String.class);
        parentApplicationContext.registerSingleton(ANOTHER_BEAN_KEY, String.class);
        Collection<String> values = springRegistry.lookupObjects(String.class);
        assertThat(values.size(), is(2));
    } 
 
    @Test
    public void lookupByIdReturnsApplicationContextBean() 
    { 
        createSpringRegistryWithParentContext(); 
        applicationContext.registerSingleton(BEAN_KEY, String.class);
        parentApplicationContext.registerSingleton(BEAN_KEY, Integer.class);
        assertThat(springRegistry.get(BEAN_KEY), is(instanceOf(String.class)));
    } 
 

6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getStaticMessageSource, refresh
		assertEquals("bar", exp.getValue(context));
	} 
 
	public void testResolveMessage() { 
		MockRequestContext context = new MockRequestContext();
		StaticApplicationContext ac = new StaticApplicationContext();
		ac.getStaticMessageSource().addMessage("foo", Locale.FRANCE, "bar");
		ac.refresh();
		context.getRootFlow().setApplicationContext(ac);
		context.getMockExternalContext().setLocale(Locale.FRANCE);
		Expression exp = parser.parseExpression("resourceBundle.foo",
				new FluentParserContext().evaluate(RequestContext.class)); 
		assertEquals("bar", exp.getValue(context));
	} 
 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:registerSingleton, refresh
 
    public void addStepMother(StepMother instance) {
        if (appContext == null) {
            mother.set(instance);
 
            StaticApplicationContext parent = new StaticApplicationContext();
            parent.registerSingleton("stepMother", StepMotherFactory.class);
            parent.refresh();
 
            String springXml = System.getProperty("cuke4duke.springXml", "cucumber.xml");
            appContext = new ClassPathXmlApplicationContext(new String[]{springXml}, parent);
            if (mother.get() != null) {
                throw new IllegalStateException("Expected ObjectMotherFactory to snatch up the thread local. Concurrent runs?");
            } 
        } 
    } 
 
    @SuppressWarnings("unchecked") 
    public <T> T getComponent(Class<T> type) {
        List beans = new ArrayList(appContext.getBeansOfType(type).values());
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
	} 
 
	private XsltView getXsltView(String templatePath) { 
		XsltView view = new XsltView(); 
		view.setUrl(templatePath); 
		view.setApplicationContext(new StaticApplicationContext()); 
		view.initApplicationContext(); 
		return view; 
	} 
 
	private Resource getProductDataResource() { 
		return new ClassPathResource("productData.xml", getClass()); 
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:getStaticMessageSource, refresh
		assertEquals(null, exp.getValue(context));
	} 
 
	public void testResolveMessage() { 
		MockRequestContext context = new MockRequestContext();
		StaticApplicationContext ac = new StaticApplicationContext();
		ac.getStaticMessageSource().addMessage("foo", Locale.FRANCE, "bar");
		ac.refresh();
		context.getRootFlow().setApplicationContext(ac);
		context.getMockExternalContext().setLocale(Locale.FRANCE);
		Expression exp = parser.parseExpression("resourceBundle.foo",
				new FluentParserContext().evaluate(RequestContext.class)); 
		assertEquals("bar", exp.getValue(context));
	} 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
See Code Examples for Spring Framework StaticApplicationContext Methods: