當前位置: 首頁>>代碼示例>>Java>>正文


Java ConfigurableWebApplicationContext.setConfigLocation方法代碼示例

本文整理匯總了Java中org.springframework.web.context.ConfigurableWebApplicationContext.setConfigLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurableWebApplicationContext.setConfigLocation方法的具體用法?Java ConfigurableWebApplicationContext.setConfigLocation怎麽用?Java ConfigurableWebApplicationContext.setConfigLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.web.context.ConfigurableWebApplicationContext的用法示例。


在下文中一共展示了ConfigurableWebApplicationContext.setConfigLocation方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
/**
 * 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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:40,代碼來源:FrameworkServlet.java

示例2: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@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;
}
 
開發者ID:cuba-platform,項目名稱:cuba,代碼行數:27,代碼來源:SingleAppDispatcherServlet.java

示例3: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
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;
}
 
開發者ID:pulsarIO,項目名稱:realtime-analytics,代碼行數:26,代碼來源:MetricDispatcherServlet.java

示例4: createWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
protected WebApplicationContext createWebApplicationContext(ServletContext servletContext, ApplicationContext parent)
		throws BeansException {

	ConfigurableWebApplicationContext wac = new TavernXmlWebApplicationContext(pluginContext);
       try {
           wac.setServletContext(servletContext);
           wac.setConfigLocation(application.getConfig().getContextPath() == null ? servletContext
                   .getInitParameter(CONFIG_LOCATION_PARAM) : application.getConfig().getContextPath());
           customizeContext(servletContext, wac);
       } catch (Exception e){
           logger.error("init fail "+application,e);
       }
	return wac;
}
 
開發者ID:code4craft,項目名稱:tavern,代碼行數:15,代碼來源:SpringTavernContextLoader.java

示例5: contextInitialized

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "REC_CATCH_EXCEPTION")
public void contextInitialized(ServletContextEvent servletContextEvent) {

	ServletContext servletContext = servletContextEvent.getServletContext();

	StringBuilder configLocation = new StringBuilder();
	configLocation.append("classpath:org/geomajas/spring/geomajasContext.xml");
	String additionalLocations = servletContext.getInitParameter(CONFIG_LOCATION_PARAMETER);
	if (null != additionalLocations) {
		for (String onePart : additionalLocations.split("\\s")) {
			String part = onePart.trim();
			if (part.length() > 0) {
				configLocation.append(',');
				int pos = part.indexOf(':');
				if (pos < 0) {
					// no protocol specified, use classpath.
					configLocation.append(GeomajasConstant.CLASSPATH_URL_PREFIX);
				} else if (0 == pos) {
					// location starts with colon, use default application context 
					part = part.substring(1);
				}
				configLocation.append(part);
			}
		}
	}
	ConfigurableWebApplicationContext applicationContext = new XmlWebApplicationContext();

	// Assign the best possible id value.
	String id;
	try {
		String contextPath = (String) ServletContext.class.getMethod("getContextPath").invoke(servletContext);
		id = ObjectUtils.getDisplayString(contextPath);
	} catch (Exception ex) {
		// Servlet <= 2.4: resort to name specified in web.xml, if any.
		String servletContextName = servletContext.getServletContextName();
		id = ObjectUtils.getDisplayString(servletContextName);			
	}

	applicationContext.setId("Geomajas:" + id);
	applicationContext.setServletContext(servletContext);
	applicationContext.setConfigLocation(configLocation.toString());
	applicationContext.refresh();

	ApplicationContextUtil.setApplicationContext(servletContext, applicationContext);
	servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
}
 
開發者ID:geomajas,項目名稱:geomajas-project-server,代碼行數:47,代碼來源:GeomajasContextListener.java


注:本文中的org.springframework.web.context.ConfigurableWebApplicationContext.setConfigLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。