當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。