当前位置: 首页>>代码示例>>Java>>正文


Java ConfigurableWebApplicationContext.setId方法代码示例

本文整理汇总了Java中org.springframework.web.context.ConfigurableWebApplicationContext.setId方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableWebApplicationContext.setId方法的具体用法?Java ConfigurableWebApplicationContext.setId怎么用?Java ConfigurableWebApplicationContext.setId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.ConfigurableWebApplicationContext的用法示例。


在下文中一共展示了ConfigurableWebApplicationContext.setId方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureAndRefreshWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
	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
		if (this.contextId != null) {
			wac.setId(this.contextId);
		}
		else {
			// Generate default id...
			wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
					ObjectUtils.getDisplayString(getServletContext().getContextPath()) + "/" + getServletName());
		}
	}

	wac.setServletContext(getServletContext());
	wac.setServletConfig(getServletConfig());
	wac.setNamespace(getNamespace());
	wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

	// 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(getServletContext(), getServletConfig());
	}

	postProcessWebApplicationContext(wac);
	applyInitializers(wac);
	wac.refresh();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:32,代码来源:FrameworkServlet.java

示例2: initialize

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
@Override
	public void initialize(ConfigurableWebApplicationContext applicationContext) {
		applicationContext.setId(UUID.randomUUID().toString().substring(0, 8)); // make it easy to identify in logs
//		final WebPropertySource webPs = new WebPropertySource("webConfig", applicationContext.getServletContext());
//		applicationContext.getEnvironment().getPropertySources().addLast(webPs);
//		final CustomScopeConfigurer scopeConfigurer = new CustomScopeConfigurer();
//		scopeConfigurer.setScopes(ImmutableMap.<String, Object>of(WebApplicationContext.SCOPE_REQUEST, new RequestOrCommandScope()));
//		applicationContext.addBeanFactoryPostProcessor(scopeConfigurer);
	}
 
开发者ID:ceefour,项目名称:atmoboot,代码行数:10,代码来源:AppInitializer.java

示例3: configureAndRefreshWebApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //导入方法依赖的package包/类
protected void configureAndRefreshWebApplicationContext(ConfigurableWebApplicationContext wac) {
	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
		if (this.contextId != null) {
			wac.setId(this.contextId);
		}
		else {
			// Generate default id...
			ServletContext sc = getServletContext();
			if (sc.getMajorVersion() == 2 && sc.getMinorVersion() < 5) {
				// Servlet <= 2.4: resort to name specified in web.xml, if any.
				String servletContextName = sc.getServletContextName();
				if (servletContextName != null) {
					wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + servletContextName +
							"." + getServletName());
				}
				else {
					wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + getServletName());
				}
			}
			else {
				// Servlet 2.5's getContextPath available!
				wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX +
						ObjectUtils.getDisplayString(sc.getContextPath()) + "/" + getServletName());
			}
		}
	}

	wac.setServletContext(getServletContext());
	wac.setServletConfig(getServletConfig());
	wac.setNamespace(getNamespace());
	wac.addApplicationListener(new SourceFilteringListener(wac, new ContextRefreshListener()));

	// 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(getServletContext(), getServletConfig());
	}

	postProcessWebApplicationContext(wac);
	applyInitializers(wac);
	wac.refresh();
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:47,代码来源:FrameworkServlet.java

示例4: 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.setId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。