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);
}
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);
}
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");
}
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);
}
use of org.springframework.context.ApplicationContext in project spring-framework by spring-projects.
the class AutoProxyLazyInitTests method withNonStaticBeanMethodAndInterface.
@Test
public void withNonStaticBeanMethodAndInterface() {
MyBeanImpl.initialized = false;
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNonStaticAndInterface.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
bean.doIt();
assertTrue(MyBeanImpl.initialized);
}
Aggregations