Search in sources :

Example 11 with ConfigurableWebApplicationContext

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;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)

Example 12 with ConfigurableWebApplicationContext

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));
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 13 with ConfigurableWebApplicationContext

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;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ApplicationContextException(org.springframework.context.ApplicationContextException)

Example 14 with ConfigurableWebApplicationContext

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;
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) CubaXmlWebApplicationContext(com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext) Nonnull(javax.annotation.Nonnull)

Example 15 with ConfigurableWebApplicationContext

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);
    });
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ReactiveWebApplicationContextRunner(org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner) WebApplicationContextRunner(org.springframework.boot.test.context.runner.WebApplicationContextRunner) FilterRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.FilterRegistrationMappingDescription) DispatcherServletMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletMappingDescription) ContextMappings(org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings) ServletRegistrationMappingDescription(org.springframework.boot.actuate.web.mappings.servlet.ServletRegistrationMappingDescription) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)20 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)7 Test (org.junit.jupiter.api.Test)6 File (java.io.File)4 FileSystemResource (org.springframework.core.io.FileSystemResource)4 CubaXmlWebApplicationContext (com.haulmont.cuba.core.sys.CubaXmlWebApplicationContext)3 List (java.util.List)3 ContextMappings (org.springframework.boot.actuate.web.mappings.MappingsEndpoint.ContextMappings)3 ReactiveWebApplicationContextRunner (org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner)3 WebApplicationContextRunner (org.springframework.boot.test.context.runner.WebApplicationContextRunner)3 MockServletContext (org.springframework.mock.web.MockServletContext)3 WebApplicationContext (org.springframework.web.context.WebApplicationContext)3 SingleAppResourcePatternResolver (com.haulmont.cuba.core.sys.SingleAppResourcePatternResolver)2 DispatcherServletMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.DispatcherServletMappingDescription)2 FilterRegistrationMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.FilterRegistrationMappingDescription)2 ServletRegistrationMappingDescription (org.springframework.boot.actuate.web.mappings.servlet.ServletRegistrationMappingDescription)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 PageContext (jakarta.servlet.jsp.PageContext)1