Spring Framework AbstractApplicationContext - 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 AbstractApplicationContext class.

This code example shows how to use the following methods:getBean, load, refresh
		assertEquals("SpringSource", company);
	} 
 
	@Test
	public void testLoadingMultipleConfigFilesWithRelativeClass() { 
		GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
		ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
		ctx.refresh();
 
		Object framework = ctx.getBean("framework");
		assertNotNull("could not find framework bean", framework);
		assertEquals("Grails", framework);
 
		Object company = ctx.getBean("company");
		assertNotNull("could not find company bean", company);
		assertEquals("SpringSource", company);
	} 
 
	@Test(expected = BeanDefinitionParsingException.class)
	public void testConfigFileParsingError() { 
8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:register, getBean, getBean, refresh
 
    @Test
    public void processEngineWithJpaEntityManager() throws Exception {
        AnnotationConfigApplicationContext context = this.context(DataSourceAutoConfiguration.class,
                HibernateJpaAutoConfiguration.class, JpaProcessEngineAutoConfiguration.JpaConfiguration.class); 
        Assert.assertNotNull("entityManagerFactory should not be null", context.getBean(EntityManagerFactory.class));
        Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
        SpringProcessEngineConfiguration configuration = context.getBean(SpringProcessEngineConfiguration.class);
        Assert.assertNotNull("the " + SpringProcessEngineConfiguration.class.getName() + " should not be null", configuration);
        Assert.assertNotNull(configuration.getJpaEntityManagerFactory());
    } 
 
    @Test
    public void processEngineWithBasicDataSource() throws Exception {
        AnnotationConfigApplicationContext context = this.context(
                DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class); 
        Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
    } 
 
    @Test

8
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:sleep, close, getBean
 
		final String sourceFileName = "README.md";
		final String destinationFileName = sourceFileName +"_foo";
 
		final ClassPathXmlApplicationContext ac =
			new ClassPathXmlApplicationContext("/META-INF/spring/integration/SftpOutboundTransferSample-context.xml", SftpOutboundTransferSample.class);
		@SuppressWarnings("unchecked") 
		SessionFactory<LsEntry> sessionFactory = ac.getBean(CachingSessionFactory.class);
		RemoteFileTemplate<LsEntry> template = new RemoteFileTemplate<LsEntry>(sessionFactory);
		SftpTestUtils.createTestFiles(template); // Just the directory
 
		try { 
			final File file = new File(sourceFileName);
 
			Assert.isTrue(file.exists(), String.format("File '%s' does not exist.", sourceFileName));
 
			final Message<File> message = MessageBuilder.withPayload(file).build();
			final MessageChannel inputChannel = ac.getBean("inputChannel", MessageChannel.class);
 
			inputChannel.send(message);

7
CodeRank
Experience pair programming with AI  Get Codota for Java
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
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:refresh, registerShutdownHook, getDefaultListableBeanFactory
	public final ConfigurableApplicationContext loadContext(String... locations) throws Exception {
		if (logger.isDebugEnabled()) {
			logger.debug(String.format("Loading ApplicationContext for locations [%s].",
				StringUtils.arrayToCommaDelimitedString(locations)));
		} 
		GenericApplicationContext context = new GenericApplicationContext();
		prepareContext(context);
		customizeBeanFactory(context.getDefaultListableBeanFactory());
		createBeanDefinitionReader(context).loadBeanDefinitions(locations);
		AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
		customizeContext(context);
		context.refresh();
		context.registerShutdownHook();
		return context;
	} 
 
	/** 
	 * Prepare the {@link GenericApplicationContext} created by this {@code ContextLoader}. 
	 * Called <i>before</i> bean definitions are read. 
	 * 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getBean, getBean
public class TestSpring { 
 
    @Test
    public void testBeanSelection() { 
        // Selection of the Test Application Context 
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
                "appContextTest2.xml"); 
        // Check that the initializer is present 
        Object obj = context.getBean("ioInitializer");
        Assert.assertNotNull(obj);
        Assert.assertTrue(obj instanceof ImageIOInitializer);
 
        // Ensure that the excluded spi are present 
        ImageIOInitializer init = (ImageIOInitializer) obj;
        List<String> excluded = init.getExcludedSpis();
        Assert.assertNotNull(excluded);
        Assert.assertTrue(excluded.isEmpty());
 
        // Ensure that a decoder is present 
        Object obj2 = context.getBean("TIFFDecoder");

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:load, getBeanDefinitionNames, getEnvironment, refresh
 
public class ActiveMQTest { 
 
	@Test
	public void testJmsConnectionFactory() { 
		GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
		applicationContext.getEnvironment().setActiveProfiles("test");
		applicationContext.load("/jmsContext.xml");
		applicationContext.refresh();
		String[] profiles = applicationContext.getEnvironment().getActiveProfiles();
		Assert.assertTrue(ArrayUtils.contains(profiles, "test"));
		String[] beanNames = applicationContext.getBeanDefinitionNames();
		Assert.assertTrue(ArrayUtils.contains(beanNames, "jmsConnectionFactory"));
	} 
 
} 
7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:registerShutdownHook, getBean, stop
      String contextFile = "classpath:Dempsy-localVm.xml";
      context = null;
      try 
      { 
         // Initialize Spring 
         context = new ClassPathXmlApplicationContext(new String[] {appCtxFilename, contextFile});
         context.registerShutdownHook();
      } 
      catch(Throwable e)
      { 
         logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e);
         throw e;
      } 
       
      if(context != null)
      { 
         try 
         { 
            Dempsy dempsy = context.getBean(Dempsy.class);
            if (startUp)

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:registerShutdownHook, getBean, stop
      String contextFile = "classpath:Dempsy-distributed.xml";
      ClassPathXmlApplicationContext context = null;
      try 
      { 
         // Initialize Spring 
         context = new ClassPathXmlApplicationContext(new String[] {appCtxFilename, contextFile});
         context.registerShutdownHook();
      } 
      catch(Throwable e)
      { 
         logger.error(MarkerFactory.getMarker("FATAL"), "Failed to start the application ", e);
         throw e;
      } 
      if(context != null)
      { 
         try 
         { 
            context.getBean(Dempsy.class).waitToBeStopped();
         } 
         catch(InterruptedException e)

7
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getBean, close
 
        // It should be the same broker; 
        assertEquals(bs1, bs2);
 
        // Even if we load up another context, it should still be the same broker. 
        ClassPathXmlApplicationContext context2 = new ClassPathXmlApplicationContext(config);
 
        BrokerService bs3 = (BrokerService) context2.getBean("broker1");
        assertNotNull(bs3);
        BrokerService bs4 = (BrokerService) context2.getBean("broker2");
        assertNotNull(bs4);
 
        // It should be the same broker; 
        assertEquals(bs1, bs3);
        assertEquals(bs1, bs4);
 
        // And it should be started. 
        assertTrue(bs1.isStarted());
 
        // should still be started asfter the 2nd context closes. 

7
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Spring Framework AbstractApplicationContext Methods: