当前位置: 首页>>代码示例>>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;未经允许,请勿转载。