Example usage for org.springframework.web.context ConfigurableWebApplicationContext setConfigLocation

List of usage examples for org.springframework.web.context ConfigurableWebApplicationContext setConfigLocation

Introduction

In this page you can find the example usage for org.springframework.web.context ConfigurableWebApplicationContext setConfigLocation.

Prototype

void setConfigLocation(String configLocation);

Source Link

Document

Set the config locations for this web application context in init-param style, i.e.

Usage

From source file:org.springside.modules.test.spring.SpringWebTestHelper.java

/**
 * ServletContext?Spring WebApplicationContext.
 * //  w w  w.java2  s.  c  o  m
 * @param applicationContext ApplicationContext.
 */
public static void initWebApplicationContext(MockServletContext servletContext,
        ApplicationContext applicationContext) {
    ConfigurableWebApplicationContext wac = new XmlWebApplicationContext();
    wac.setParent(applicationContext);
    wac.setServletContext(servletContext);
    wac.setConfigLocation("");
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
    wac.refresh();
}

From source file:org.n52.wfs.WfsDispatcherServlet.java

@Override
protected void postProcessWebApplicationContext(ConfigurableWebApplicationContext wac) {
    super.postProcessWebApplicationContext(wac);
    ServletContext servletContext = wac.getServletContext();
    wac.setConfigLocation(getConfigLocation(servletContext));
}

From source file:com.j2trp.test.util.jersey.spi.spring.container.servlet.SpringServlet.java

private ConfigurableApplicationContext getChildContext(String contextConfigLocation) {
    final ConfigurableWebApplicationContext ctx = new XmlWebApplicationContext();
    ctx.setParent(getDefaultContext());// w  w w.  ja  va 2s  . c o m
    ctx.setServletContext(getServletContext());
    ctx.setConfigLocation(contextConfigLocation);

    ctx.refresh();
    return ctx;
}

From source file:com.ebay.pulsar.metric.server.MetricDispatcherServlet.java

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 + "]");
    }//from w  ww.j a  v a 2 s  .  c  om
    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;
}

From source file:com.helpinput.spring.servlet.mvc.EnhanceDispachServlet.java

@Override
protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) {
    ContextHolder.beanRegistIntercpterHolder.register(new UrlInterceptorBeanRegistInterceptor());

    Class<?> contextClass = getContextClass();
    if (logger.isDebugEnabled()) {
        logger.debug("Servlet with name '" + getServletName()
                + "' will try to create custom WebApplicationContext context of class '"
                + contextClass.getName() + "'" + ", using parent context [" + parent + "]");
    }/*  w w  w  .j ava2s .  c om*/
    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;
    if (parent instanceof ConfigurableWebApplicationContext)
        wac = (ConfigurableWebApplicationContext) parent;
    else {
        wac = (ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);
        wac.setEnvironment(getEnvironment());
        wac.setParent(parent);
        wac.setConfigLocation(getContextConfigLocation());
        configureAndRefreshWebApplicationContext(wac);
    }
    return wac;
}

From source file:org.sarons.spring4me.web.filter.PageFilter.java

protected ConfigurableWebApplicationContext initPageApplicationContext() {
    WebApplicationContext root = WebApplicationContextUtils.getWebApplicationContext(getServletContext());
    ///*w  ww  . j  av a  2  s  . c o m*/
    ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
            .instantiateClass(contextClass);
    wac.setParent(root);
    wac.setServletContext(getServletContext());
    wac.setServletConfig(new DelegatingServletConfig(getServletContext()));
    wac.setNamespace(getNamespace());
    wac.setConfigLocation(getWidgetConfigLocation());
    wac.refresh();
    //
    return wac;
}

From source file:com.xinlv.test.MockContextLoader.java

@Override
public ConfigurableApplicationContext loadContext(String... locations) throws Exception {

    ConfigurableWebApplicationContext context = new XmlWebApplicationContext();
    MockServletContext servletContext = new MockServletContext("") {
        @Override//from   w w w  . ja  va  2  s.  c o  m
        public String getRealPath(String arg0) {
            return System.getProperty("java.io.tmpdir");
        }
    };
    servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
    context.setServletContext(servletContext);
    String configLocation = "/xinlv-test-context.xml";
    context.setConfigLocation(configLocation);
    /*String[] configLocations = PortalContextLoaderListener.locateConfigLocations(locations);
    context.setConfigLocations(configLocations);*/
    context.refresh();
    context.registerShutdownHook();
    return context;
}

From source file:com.katsu.dwm.springframework.Loader.java

public void load(File jar, Properties properties) throws MalformedURLException {
    ConfigurableWebApplicationContext wac = (ConfigurableWebApplicationContext) BeanUtils
            .instantiateClass(XmlWebApplicationContext.class);
    //FIXME//from w  w w  .  j ava 2  s  .  co  m
    wac.setId("test-context");
    wac.setParent(applicationContext);
    wac.setServletContext(((XmlWebApplicationContext) applicationContext).getServletContext());
    //wac.setServletConfig(((XmlWebApplicationContext) applicationContext).getServletConfig());
    //wac.setNamespace(((XmlWebApplicationContext) applicationContext).getNamespace());
    wac.setConfigLocation(properties.getProperty(LoaderConst.CONTEXT_LOCATION.getValue()));
    //wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));
    wac.refresh();

    wac.getServletContext().setAttribute("test-context", wac);
}

From source file:com.dhcc.framework.web.context.DhccContextLoader.java

protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac,
        ServletContext sc) {//from w  ww.  jav a  2s. co  m
    Log logger = LogFactory.getLog(DhccContextLoader.class);
    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...
            if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
                // Servlet <= 2.4: resort to name specified in web.xml, if any.
                wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX
                        + ObjectUtils.getDisplayString(sc.getServletContextName()));
            } else {
                wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX
                        + ObjectUtils.getDisplayString(sc.getContextPath()));
            }
        }
    }

    wac.setServletContext(sc);
    String initParameter = sc.getInitParameter(CONFIG_LOCATION_PARAM);
    if (isMicrokernelStart(sc)) {
        initParameter = "classpath:codeTemplate/applicationSetupContext.xml";
        logger.error("because cant't  connect to db or setup flg is 0 so init application as  Microkernel ");
    } else {
        logger.info("initParameter==" + initParameter);
    }
    if (initParameter != null) {
        wac.setConfigLocation(initParameter);
    }
    customizeContext(sc, wac);
    wac.refresh();
}

From source file:org.impalaframework.web.spring.loader.BaseImpalaContextLoader.java

/**
 * Overrides the empty {@link ContextLoader#customizeContext(ServletContext, ConfigurableWebApplicationContext)}
 * by setting the parent {@link ApplicationContext} to use an empty location if the current location is simply the default,
 * and this does not exist. Effectively provides transparent support for "empty" parent {@link ApplicationContext}
 *//*from   w  ww .j a  va  2  s  . c om*/
@Override
protected void customizeContext(ServletContext servletContext,
        ConfigurableWebApplicationContext applicationContext) {

    final String initParameter = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
    if (initParameter == null) {
        final ServletContextResource servletContextResource = new ServletContextResource(servletContext,
                XmlWebApplicationContext.DEFAULT_CONFIG_LOCATION);
        if (!servletContextResource.exists()) {
            try {
                applicationContext.setConfigLocation("classpath:META-INF/impala-web-empty.xml");
            } catch (UnsupportedOperationException e) {
                //no longer supported in Spring 3.2, so ignore this
            }
        }
    }
}