@Test @WithMockUser public void supportAuthenticationManagerInParent() { try (AnnotationConfigWebApplicationContext parent = new AnnotationConfigWebApplicationContext()) { parent.register(Sec2479ParentConfig.class); parent.refresh(); try (AnnotationConfigWebApplicationContext child = new AnnotationConfigWebApplicationContext()) { child.setParent(parent); child.register(Sec2479ChildConfig.class); child.refresh(); this.spring.context(child).autowire(); assertThatThrownBy(() -> this.service.preAuthorize()) .isInstanceOf(AccessDeniedException.class); } } }
@Override protected WebApplicationContext createServletApplicationContext() { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.setParent(root); appContext.scan(packagesToScan); return appContext; }
protected WebApplicationContext applicationContext() { if (applicationContext == null) { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); Set<Class<?>> annotatedClasses = annotatedClasses(); if (annotatedClasses != null) { annotatedClasses.iterator().forEachRemaining(webApplicationContext::register); } Set<? extends BeanFactoryPostProcessor> beanFactoryPostProcessors = beanFactoryPostProcessors(); if (beanFactoryPostProcessors != null) { beanFactoryPostProcessors.iterator().forEachRemaining(webApplicationContext::addBeanFactoryPostProcessor); } if (this.rootApplicationContext != null) { webApplicationContext.setParent(this.rootApplicationContext); webApplicationContext.setEnvironment((ConfigurableEnvironment) rootApplicationContext.getEnvironment()); } applicationContext = webApplicationContext; } return (WebApplicationContext) applicationContext; }
protected WebApplicationContext applicationContext() { if (applicationContext == null) { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); Set<Class<?>> annotatedClasses = annotatedClasses(); if (annotatedClasses != null) { annotatedClasses.iterator().forEachRemaining(webApplicationContext::register); } Set<? extends BeanFactoryPostProcessor> beanFactoryPostProcessors = beanFactoryPostProcessors(); if (beanFactoryPostProcessors != null) { beanFactoryPostProcessors.iterator().forEachRemaining(webApplicationContext::addBeanFactoryPostProcessor); } if (this.rootApplicationContext != null) { webApplicationContext.setParent(this.rootApplicationContext); webApplicationContext.setEnvironment((ConfigurableEnvironment) rootApplicationContext.getEnvironment()); } applicationContext = webApplicationContext; } return (WebApplicationContext) applicationContext; }
protected WebApplicationContext applicationContext() { if (applicationContext == null) { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); Set<Class<?>> annotatedClasses = annotatedClasses(); if (annotatedClasses != null) { annotatedClasses.iterator().forEachRemaining(webApplicationContext::register); } Set<? extends BeanFactoryPostProcessor> beanFactoryPostProcessors = beanFactoryPostProcessors(); if (beanFactoryPostProcessors != null) { beanFactoryPostProcessors.iterator().forEachRemaining(webApplicationContext::addBeanFactoryPostProcessor); } if (this.rootApplicationContext != null) { webApplicationContext.setParent(this.rootApplicationContext); webApplicationContext.setEnvironment((ConfigurableEnvironment) rootApplicationContext.getEnvironment()); } applicationContext = webApplicationContext; } return (WebApplicationContext) applicationContext; }
/** * Initializes Spring and Spring MVC. */ private ServletRegistration.Dynamic initSpring(ServletContext servletContext, WebApplicationContext 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; }
@Override protected void doStart() throws Exception { AbstractHandler noContentHandler = new NoContentOutputErrorHandler(); // This part is needed to avoid WARN while starting container. noContentHandler.setServer(server); server.addBean(noContentHandler); // Create the servlet context final ServletContextHandler context = new ServletContextHandler(server, entrypoint, ServletContextHandler.SESSIONS); // REST configuration final ServletHolder servletHolder = new ServletHolder(ServletContainer.class); servletHolder.setInitParameter("javax.ws.rs.Application", GraviteeApplication.class.getName()); servletHolder.setInitOrder(0); context.addServlet(servletHolder, "/*"); // Spring configuration System.setProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME, "basic"); AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); webApplicationContext.register(SecurityConfiguration.class); webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment()); webApplicationContext.setParent(applicationContext); context.addEventListener(new ContextLoaderListener(webApplicationContext)); // Spring Security filter context.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")),"/*", EnumSet.allOf(DispatcherType.class)); // start the server server.start(); }
@Override public WebApplicationContext createWebContext(ApplicationContext rootContext, ServletContextHandler handler, Config config) { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.setParent(rootContext); context.setServletContext(handler.getServletContext()); registerConfigClasses(context, config); context.refresh(); return context; }
webContext.setParent(applicationContext); webContext.register(getApiModuleConfigurationClass()); return new DispatcherServlet(webContext);
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; }
@Bean(name=HTTP_TRANSPORT_CHILD_CONTEXT_BEAN_NAME) public SpringContextWrapper transportWebMvcContext(ConfigurableWebApplicationContext parentContext, ServletContextHandler servletContextHandler){ AnnotationConfigWebApplicationContext transportWebMvcContext = new AnnotationConfigWebApplicationContext(); transportWebMvcContext.setDisplayName("httpTransport-webMvcContext"); transportWebMvcContext.setServletContext(servletContextHandler.getServletContext()); transportWebMvcContext.setParent(parentContext); transportWebMvcContext.setEnvironment(parentContext.getEnvironment()); transportWebMvcContext.register(SpringMvcConfiguration.class); transportWebMvcContext.register(PropertySourcesPlaceholderConfigurer.class); transportWebMvcContext.refresh(); return new SpringContextWrapper(transportWebMvcContext); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { // root context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfig.class); // configuration class for root context rootContext.scan("...service", "...dao"); // scan only some packages servletContext.addListener(new ContextLoaderListener(rootContext)); // dispatcher servlet 1 AnnotationConfigWebApplicationContext webContext1 = new AnnotationConfigWebApplicationContext(); webContext1.setParent(rootContext); webContext1.register(WebConfig1.class); // configuration class for servlet 1 webContext1.scan("...web1"); // scan some other packages ServletRegistration.Dynamic dispatcher1 = servletContext.addServlet("dispatcher1", new DispatcherServlet(webContext1)); dispatcher1.setLoadOnStartup(1); dispatcher1.addMapping("/subcontext1"); // dispatcher servlet 2 ... }
context.setParent(parent);
context.setParent(parent);
rootWebContext.setParent(MangoRuntimeContextConfiguration.getRuntimeContext()); rootWebContext.register(MangoRootWebContextConfiguration.class); jspDispatcherContext.setParent(rootWebContext); jspDispatcherContext.register(MangoJspDispatcherConfiguration.class); rootRestContext.setParent(rootWebContext); rootRestContext.register(RootRestDispatcherConfiguration.class);