use of org.springframework.web.context.ConfigurableWebApplicationContext in project alf.io by alfio-event.
the class Initializer method createRootApplicationContext.
@Override
protected WebApplicationContext createRootApplicationContext() {
ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext());
Objects.requireNonNull(ctx, "Something really bad is happening...");
this.environment = ctx.getEnvironment();
return ctx;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-boot-admin by codecentric.
the class DefaultApplicationFactoryTest method publishApplicationReadyEvent.
private void publishApplicationReadyEvent(DefaultApplicationFactory factory, Integer serverport, Integer managementport) {
MockEnvironment env = new MockEnvironment();
if (serverport != null) {
env.setProperty("local.server.port", serverport.toString());
}
if (managementport != null) {
env.setProperty("local.management.port", managementport.toString());
}
ConfigurableWebApplicationContext context = mock(ConfigurableWebApplicationContext.class);
when(context.getEnvironment()).thenReturn(env);
factory.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-framework by spring-projects.
the class FrameworkServlet method createWebApplicationContext.
/**
* Instantiate the WebApplicationContext for this servlet, either a default
* {@link org.springframework.web.context.support.XmlWebApplicationContext}
* or a {@link #setContextClass custom context class}, if set.
* <p>This implementation expects custom contexts to implement the
* {@link org.springframework.web.context.ConfigurableWebApplicationContext}
* interface. Can be overridden in subclasses.
* <p>Do not forget to register this servlet instance as application listener on the
* created context (for triggering its {@link #onRefresh callback}, and to call
* {@link org.springframework.context.ConfigurableApplicationContext#refresh()}
* before returning the context instance.
* @param parent the parent ApplicationContext to use, or {@code null} if none
* @return the WebApplicationContext for this servlet
* @see org.springframework.web.context.support.XmlWebApplicationContext
*/
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
Class<?> contextClass = getContextClass();
if (this.logger.isDebugEnabled()) {
this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + contextClass.getName() + "'" + ", using parent context [" + parent + "]");
}
if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {
throw new ApplicationContextException("Fatal initialization error in servlet with name '" + getServletName() + "': custom WebApplicationContext class [" + contextClass.getName() + "] is not of type ConfigurableWebApplicationContext");
}
ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
wac.setEnvironment(getEnvironment());
wac.setParent(parent);
wac.setConfigLocation(getContextConfigLocation());
configureAndRefreshWebApplicationContext(wac);
return wac;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project cuba by cuba-platform.
the class SingleAppDispatcherServlet method createWebApplicationContext.
@Override
@Nonnull
protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) {
if (this.logger.isDebugEnabled()) {
this.logger.debug(String.format("Servlet with name '%s' will try to create custom WebApplicationContext context of class '%s', using parent context [%s]", getServletName(), CubaXmlWebApplicationContext.class.getName(), parent));
}
ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext();
String contextConfigLocation = getContextConfigLocation();
if (contextConfigLocation == null) {
throw new RuntimeException("Unable to determine context config location");
}
wac.setEnvironment(getEnvironment());
wac.setParent(parent);
wac.setConfigLocation(contextConfigLocation);
configureAndRefreshWebApplicationContext(wac);
return wac;
}
use of org.springframework.web.context.ConfigurableWebApplicationContext in project spring-boot by spring-projects.
the class MappingsEndpointTests method servletWebMappingsWithPathPatternParser.
@Test
void servletWebMappingsWithPathPatternParser() {
Supplier<ConfigurableWebApplicationContext> contextSupplier = prepareContextSupplier();
new WebApplicationContextRunner(contextSupplier).withUserConfiguration(EndpointConfiguration.class, ServletWebConfiguration.class, PathPatternParserConfiguration.class).run((context) -> {
ContextMappings contextMappings = contextMappings(context);
assertThat(contextMappings.getParentId()).isNull();
assertThat(contextMappings.getMappings()).containsOnlyKeys("dispatcherServlets", "servletFilters", "servlets");
Map<String, List<DispatcherServletMappingDescription>> dispatcherServlets = mappings(contextMappings, "dispatcherServlets");
assertThat(dispatcherServlets).containsOnlyKeys("dispatcherServlet");
List<DispatcherServletMappingDescription> handlerMappings = dispatcherServlets.get("dispatcherServlet");
assertThat(handlerMappings).hasSize(1);
List<ServletRegistrationMappingDescription> servlets = mappings(contextMappings, "servlets");
assertThat(servlets).hasSize(1);
List<FilterRegistrationMappingDescription> filters = mappings(contextMappings, "servletFilters");
assertThat(filters).hasSize(1);
});
}
Aggregations