Java Code Examples for org.springframework.web.context.support.AnnotationConfigWebApplicationContext#setParent()

The following examples show how to use org.springframework.web.context.support.AnnotationConfigWebApplicationContext#setParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BaseRestApiConfiguration.java    From flowable-engine with Apache License 2.0 7 votes vote down vote up
protected ServletRegistrationBean registerServlet(FlowableServlet servletProperties, Class<?> baseConfig) {
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(applicationContext);
    dispatcherServletConfiguration.register(baseConfig);
    DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
    String path = servletProperties.getPath();
    String urlMapping = (path.endsWith("/") ? path + "*" : path + "/*");
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, urlMapping);
    registrationBean.setName(servletProperties.getName());
    registrationBean.setLoadOnStartup(servletProperties.getLoadOnStartup());
    registrationBean.setAsyncSupported(true);
    if (multipartConfigElement != null) {
        registrationBean.setMultipartConfig(multipartConfigElement);
    }
    return registrationBean;
}
 
Example 2
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private void initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/app/*");
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    log.debug("Registering API Servlet");
    AnnotationConfigWebApplicationContext apiDispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    apiDispatcherServletConfiguration.setParent(rootContext);
    apiDispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);

    ServletRegistration.Dynamic apiDispatcherServlet = servletContext.addServlet("apiDispatcher",
        new DispatcherServlet(apiDispatcherServletConfiguration));
    apiDispatcherServlet.addMapping("/api/*");
    apiDispatcherServlet.setLoadOnStartup(1);
    apiDispatcherServlet.setAsyncSupported(true);
}
 
Example 3
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private void initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    log.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext appDispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    appDispatcherServletConfiguration.setParent(rootContext);
    appDispatcherServletConfiguration.register(AppDispatcherServletConfiguration.class);

    log.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic appDispatcherServlet = servletContext.addServlet("appDispatcher", 
            new DispatcherServlet(appDispatcherServletConfiguration));
    appDispatcherServlet.addMapping("/app/*");
    appDispatcherServlet.setLoadOnStartup(1);
    appDispatcherServlet.setAsyncSupported(true);

    log.debug("Registering Activiti public REST API");
    AnnotationConfigWebApplicationContext apiDispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    apiDispatcherServletConfiguration.setParent(rootContext);
    apiDispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);

    ServletRegistration.Dynamic apiDispatcherServlet = servletContext.addServlet("apiDispatcher",
            new DispatcherServlet(apiDispatcherServletConfiguration));
    apiDispatcherServlet.addMapping("/api/*");
    apiDispatcherServlet.setLoadOnStartup(1);
    apiDispatcherServlet.setAsyncSupported(true);
}
 
Example 4
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 5
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 6
Source File: AbstractNemServletContextListener.java    From nem.deploy with MIT License 6 votes vote down vote up
@Override
public void contextInitialized(final ServletContextEvent event) {
	try {
		final AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext();

		webCtx.register(this.webAppInitializerClass);
		webCtx.setParent(this.appCtx);

		final ServletContext context = event.getServletContext();
		this.initialize(webCtx, context);

		context.setInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext");

		if (this.useDosFilter) {
			addDosFilter(context);
		}

		addGzipFilter(context);
		addCorsFilter(context);
	} catch (final Exception e) {
		throw new RuntimeException(String.format("Exception in contextInitialized: %s", e.toString()), e);
	}
}
 
Example 7
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 8
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 9
Source File: JPAWebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 10
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 11
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 12
Source File: WebConfigurer.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
    LOGGER.debug("Configuring Spring Web application context");
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(rootContext);
    dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

    LOGGER.debug("Registering Spring MVC Servlet");
    ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
    dispatcherServlet.addMapping("/service/*");
    dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null));
    dispatcherServlet.setLoadOnStartup(1);
    dispatcherServlet.setAsyncSupported(true);

    return dispatcherServlet;
}
 
Example 13
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
  log.debug("Configuring Spring Web application context");
  AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
  dispatcherServletConfiguration.setParent(rootContext);
  dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

  log.debug("Registering Spring MVC Servlet");
  ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
  dispatcherServlet.addMapping("/service/*");
  dispatcherServlet.setLoadOnStartup(1);
  dispatcherServlet.setAsyncSupported(true);

  return dispatcherServlet;
}
 
Example 14
Source File: ApplicationConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean apiServlet(ApplicationContext applicationContext) {
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(applicationContext);
    dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
    DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");
    registrationBean.setName("Flowable IDM App API Servlet");
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    return registrationBean;
}
 
Example 15
Source File: ApplicationConfiguration.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletRegistrationBean modelerApiServlet(ApplicationContext applicationContext) {
    AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
    dispatcherServletConfiguration.setParent(applicationContext);
    dispatcherServletConfiguration.register(ApiDispatcherServletConfiguration.class);
    DispatcherServlet servlet = new DispatcherServlet(dispatcherServletConfiguration);
    ServletRegistrationBean registrationBean = new ServletRegistrationBean(servlet, "/api/*");
    registrationBean.setName("Flowable Modeler App API Servlet");
    registrationBean.setLoadOnStartup(1);
    registrationBean.setAsyncSupported(true);
    return registrationBean;
}
 
Example 16
Source File: ManagementApiServer.java    From graviteeio-access-management with Apache License 2.0 5 votes vote down vote up
public void attachHandlers() {

        // Create the servlet context
        final ServletContextHandler context = new ServletContextHandler(this.server, entrypoint, ServletContextHandler.SESSIONS);

        // REST configuration
        final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
        servletHolder.setInitParameter("javax.ws.rs.Application", ManagementApplication.class.getName());
        servletHolder.setInitOrder(1);
        servletHolder.setAsyncSupported(true);

        AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
        webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
        webApplicationContext.setParent(applicationContext);
        webApplicationContext.setServletContext(context.getServletContext());

        webApplicationContext.register(ManagementConfiguration.class);

        context.addEventListener(new ContextLoaderListener(webApplicationContext));
        context.addServlet(servletHolder, "/*");
        context.addServlet(new ServletHolder(new DispatcherServlet(webApplicationContext)), "/auth/*");

        // X-Forwarded-* support
        context.addFilter(ForwardedHeaderFilter.class, "/*", EnumSet.allOf(DispatcherType.class));

        // Spring Security filter
        context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")), "/*", EnumSet.allOf(DispatcherType.class));
    }
 
Example 17
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
  log.debug("Configuring Spring Web application context");
  AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
  dispatcherServletConfiguration.setParent(rootContext);
  dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

  log.debug("Registering Spring MVC Servlet");
  ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
  dispatcherServlet.addMapping("/service/*");
  dispatcherServlet.setLoadOnStartup(1);
  dispatcherServlet.setAsyncSupported(true);

  return dispatcherServlet;
}
 
Example 18
Source File: JPAWebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
  log.debug("Configuring Spring Web application context");
  AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
  dispatcherServletConfiguration.setParent(rootContext);
  dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

  log.debug("Registering Spring MVC Servlet");
  ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
  dispatcherServlet.addMapping("/service/*");
  dispatcherServlet.setLoadOnStartup(1);
  dispatcherServlet.setAsyncSupported(true);

  return dispatcherServlet;
}
 
Example 19
Source File: WebConfigurer.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Initializes Spring and Spring MVC.
 */
private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) {
  log.debug("Configuring Spring Web application context");
  AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext();
  dispatcherServletConfiguration.setParent(rootContext);
  dispatcherServletConfiguration.register(DispatcherServletConfiguration.class);

  log.debug("Registering Spring MVC Servlet");
  ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration));
  dispatcherServlet.addMapping("/service/*");
  dispatcherServlet.setLoadOnStartup(1);
  dispatcherServlet.setAsyncSupported(true);

  return dispatcherServlet;
}
 
Example 20
Source File: JettyEmbeddedContainer.java    From gravitee-management-rest-api with Apache License 2.0 3 votes vote down vote up
protected ServletContextHandler configureAPI(String apiContextPath, String applicationName, Class<? extends GlobalAuthenticationConfigurerAdapter> securityConfigurationClass) {
    final ServletContextHandler childContext = new ServletContextHandler(server, apiContextPath, ServletContextHandler.SESSIONS);

    final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
    servletHolder.setInitParameter("javax.ws.rs.Application", applicationName);
    servletHolder.setInitOrder(0);
    childContext.addServlet(servletHolder, "/*");

    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(securityConfigurationClass);

    webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
    webApplicationContext.setParent(applicationContext);

    childContext.addEventListener(new ContextLoaderListener(webApplicationContext));

    // Spring Security filter
    childContext.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")),"/*", EnumSet.allOf(DispatcherType.class));
    return childContext;


}