String configLocation = getContextConfigLocation(); if (configLocation != null) { wac.setConfigLocation(configLocation);
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
String configLocation = getContextConfigLocation(); if (configLocation != null) { wac.setConfigLocation(configLocation);
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
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.setParent(parent); if (wac.getParent() == null) { ApplicationContext rootContext = (ApplicationContext) getServletContext().getAttribute("JetStreamRoot"); wac.setParent(rootContext); } wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
@Override public synchronized void setConfigLocation(String location) { this.appContext.setConfigLocation(location); }
wac.setConfigLocation(initParam);
@RunWith(TapestryIOCJUnit4ClassRunner.class) @Registry(modules={TapestryModule.class, SpringModule.class, TestModule.class}) public class MyTest { public static class TestModule { @Contribute(ApplicationContextCustomizer.class) public static void addCustomizer(OrderedConfiguration<ApplicationContextCustomizer> config) { ApplicationContextCustomizer customizer = new ApplicationContextCustomizer() { public void customizeApplicationContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) { applicationContext.setConfigLocation("classpath:/test-applicationContext.xml"); } }; config.add("mycustomizer", customizer); } } @ModuleDef public static SpringModuleDef createSpringModuleDef() { ServletContext sc = new MockServletContext(); return new SpringModuleDef(sc); } // @Inject @Test etc
wac.setConfigLocation(contextConfigLocation);
@Override protected WebApplicationContext createWebApplicationContext( ServletContext servletContext, ApplicationContext parent) throws BeansException { ConfigurableWebApplicationContext wac = new CompilationAwareXmlWebApplicationContext(); wac.setParent(parent); wac.setServletContext(servletContext); wac.setConfigLocation(servletContext.getInitParameter(CONFIG_LOCATION_PARAM)); customizeContext(servletContext, wac); wac.refresh(); //we now init the scripting system Class contextClass = determineContextClass(servletContext); if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) { throw new ApplicationContextException("Custom context class [" + contextClass.getName() + "] is not of type [" + ConfigurableWebApplicationContext.class.getName() + "]"); } return wac; }
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]"); } ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() { @Override protected ResourcePatternResolver getResourcePatternResolver() { if (dependencyJars == null || dependencyJars.isEmpty()) { throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory."); } return new SingleAppResourcePatternResolver(this, dependencyJars); } }; wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
@Override protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { if (this.logger.isDebugEnabled()) { this.logger.debug("Servlet with name '" + getServletName() + "' will try to create custom WebApplicationContext context of class '" + CubaXmlWebApplicationContext.class.getName() + "'" + ", using parent context [" + parent + "]"); } ConfigurableWebApplicationContext wac = new CubaXmlWebApplicationContext() { @Override protected ResourcePatternResolver getResourcePatternResolver() { if (dependencyJars == null || dependencyJars.isEmpty()) { throw new RuntimeException("No JARs defined for the 'web' block. " + "Please check that web.dependencies file exists in WEB-INF directory."); } return new SingleAppResourcePatternResolver(this, dependencyJars); } }; wac.setEnvironment(getEnvironment()); wac.setParent(parent); wac.setConfigLocation(getContextConfigLocation()); configureAndRefreshWebApplicationContext(wac); return wac; } }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
/** * Creates and initializes a new {@link WebApplicationContext}, with the given context as the * parent. Based on the logic in {@link FrameworkServlet#createWebApplicationContext} * * @param parent * parent application context * @param filter * wicket filter * @return instance of web application context * @throws BeansException */ protected final ConfigurableWebApplicationContext createWebApplicationContext( final WebApplicationContext parent, final WicketFilter filter) throws BeansException { webApplicationContext = newApplicationContext(); webApplicationContext.setParent(parent); webApplicationContext.setServletContext(filter.getFilterConfig().getServletContext()); webApplicationContext.setConfigLocation(getContextConfigLocation(filter)); postProcessWebApplicationContext(webApplicationContext, filter); webApplicationContext.refresh(); return webApplicationContext; }
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac, ServletContext sc) { if (ObjectUtils.identityToString(wac).equals(wac.getId())) { // The application context id is still set to its original default value // -> assign a more useful id based on available information String idParam = sc.getInitParameter(CONTEXT_ID_PARAM); if (idParam != null) { wac.setId(idParam); } else { // Generate default id... wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + ObjectUtils.getDisplayString(sc.getContextPath())); } } wac.setServletContext(sc); String configLocationParam = sc.getInitParameter(CONFIG_LOCATION_PARAM); if (configLocationParam != null) { wac.setConfigLocation(configLocationParam); } // The wac environment's #initPropertySources will be called in any case when the context // is refreshed; do it eagerly here to ensure servlet property sources are in place for // use in any post-processing or initialization that occurs below prior to #refresh ConfigurableEnvironment env = wac.getEnvironment(); if (env instanceof ConfigurableWebEnvironment) { ((ConfigurableWebEnvironment) env).initPropertySources(sc, null); } customizeContext(sc, wac); wac.refresh(); }
wac.setConfigLocation(getContextConfigLocation());
/** * Get the child application context. * <p> * The child application context is created as a child of the default * application context obtained from {@link #getDefaultContext() }. * * @param contextConfigLocation the location of the child application * context. * @return the child application context. */ protected ConfigurableApplicationContext getChildContext(String contextConfigLocation) { final ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext(); ctx.setParent(getDefaultContext()); ctx.setServletContext(getServletContext()); ctx.setConfigLocation(contextConfigLocation); ctx.refresh(); return ctx; } }
wac.setConfigLocation(getContextConfigLocation()); wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));