Search in sources :

Example 61 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class OverrideAutoConfigurationEnabledFalseIntegrationTest method disabledAutoConfiguration.

@Test
public void disabledAutoConfiguration() throws Exception {
    ApplicationContext context = this.context;
    assertThat(context.getBean(ExampleTestConfig.class)).isNotNull();
    this.thrown.expect(NoSuchBeanDefinitionException.class);
    context.getBean(ConfigurationPropertiesBindingPostProcessor.class);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

Example 62 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class ImportsContextCustomizerFactoryWithAutoConfigurationTests method testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext.

@Test
public void testClassesThatOnlyHaveDifferingUnrelatedAnnotationsShareAContext() throws InitializationError {
    RunNotifier notifier = new RunNotifier();
    new SpringJUnit4ClassRunner(DataJpaTest1.class).run(notifier);
    ApplicationContext test1Context = contextFromTest;
    new SpringJUnit4ClassRunner(DataJpaTest2.class).run(notifier);
    ApplicationContext test2Context = contextFromTest;
    assertThat(test1Context).isSameAs(test2Context);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) RunNotifier(org.junit.runner.notification.RunNotifier) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Test(org.junit.Test) DataJpaTest(org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest)

Example 63 with ApplicationContext

use of org.springframework.context.ApplicationContext in project spring-boot by spring-projects.

the class SpringBootServletInitializer method createRootApplicationContext.

protected WebApplicationContext createRootApplicationContext(ServletContext servletContext) {
    SpringApplicationBuilder builder = createSpringApplicationBuilder();
    builder.main(getClass());
    ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);
    if (parent != null) {
        this.logger.info("Root context already created (using as parent).");
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);
        builder.initializers(new ParentContextApplicationContextInitializer(parent));
    }
    builder.initializers(new ServletContextApplicationContextInitializer(servletContext));
    builder.listeners(new ServletContextApplicationListener(servletContext));
    builder.contextClass(AnnotationConfigServletWebServerApplicationContext.class);
    builder = configure(builder);
    SpringApplication application = builder.build();
    if (application.getSources().isEmpty() && AnnotationUtils.findAnnotation(getClass(), Configuration.class) != null) {
        application.getSources().add(getClass());
    }
    Assert.state(!application.getSources().isEmpty(), "No SpringApplication sources have been defined. Either override the " + "configure method or add an @Configuration annotation");
    // Ensure error pages are registered
    if (this.registerErrorPageFilter) {
        application.getSources().add(ErrorPageFilterConfiguration.class);
    }
    return run(application);
}
Also used : AnnotationConfigServletWebServerApplicationContext(org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) SpringApplication(org.springframework.boot.SpringApplication) SpringApplicationBuilder(org.springframework.boot.builder.SpringApplicationBuilder) ParentContextApplicationContextInitializer(org.springframework.boot.builder.ParentContextApplicationContextInitializer)

Example 64 with ApplicationContext

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

the class UnsupportedInterceptor method testWithDependencyChecking.

@Test
@SuppressWarnings("resource")
public void testWithDependencyChecking() {
    ApplicationContext ctx = new ClassPathXmlApplicationContext(DEPENDENCY_CHECK_CONTEXT, getClass());
    ctx.getBean("testBean");
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Test(org.junit.Test)

Example 65 with ApplicationContext

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

the class TestBean method explicitConfigClassBeanNameIsRespected.

/**
	 * Tests that specifying @Configuration(value="foo") results in registering
	 * the configuration class with bean name 'foo'.
	 */
@Test
public void explicitConfigClassBeanNameIsRespected() {
    ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithCustomName.class);
    // attempt to retrieve the instance by its specified name
    ConfigWithCustomName configObject = (ConfigWithCustomName) context.getBean("customConfigBeanName");
    assertNotNull(configObject);
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Test(org.junit.Test)

Aggregations

ApplicationContext (org.springframework.context.ApplicationContext)578 Test (org.junit.Test)262 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)179 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)44 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)37 ConfigurableMessenger (org.springframework.scripting.ConfigurableMessenger)28 File (java.io.File)25 DataSource (javax.sql.DataSource)24 Messenger (org.springframework.scripting.Messenger)24 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)21 Refreshable (org.springframework.aop.target.dynamic.Refreshable)20 StubCloudConnectorTest (org.springframework.cloud.StubCloudConnectorTest)17 HashMap (java.util.HashMap)16 SchedulerException (org.quartz.SchedulerException)16 ArrayList (java.util.ArrayList)14 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)14 WebApplicationContext (org.springframework.web.context.WebApplicationContext)14 MovieMapper (com.mapper.MovieMapper)13 Map (java.util.Map)13 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)13