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


Java ConfigurableWebApplicationContext.getEnvironment方法代碼示例

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


在下文中一共展示了ConfigurableWebApplicationContext.getEnvironment方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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 configurableWebApplicationContext) {
    ConfigurableEnvironment environment = configurableWebApplicationContext.getEnvironment();
    if (environment.getSystemEnvironment().containsKey("MONGODB_PORT_27017_TCP_ADDR") &&
            environment.getSystemEnvironment().containsKey("MONGODB_PORT_27017_TCP_PORT")) {
        environment.setActiveProfiles("docker");
    }
    if (!hasActiveProfile(environment)) {
        environment.setActiveProfiles("production");
    }
    LOGGER.info("Active profiles are {}", StringUtils.join(environment.getActiveProfiles(), ","));
}
 
開發者ID:zutherb,項目名稱:AppStash,代碼行數:13,代碼來源:ProfileInitializer.java

示例3: createRootApplicationContext

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
@Override
protected WebApplicationContext createRootApplicationContext() {
    ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext());
    Objects.requireNonNull(ctx, "Something really bad is happening...");
    ConfigurableEnvironment environment = ctx.getEnvironment();
    if(environment.acceptsProfiles(PROFILE_DEV)) {
        environment.addActiveProfile(PROFILE_HTTP);
    }
    this.environment = environment;
    return ctx;
}
 
開發者ID:alfio-event,項目名稱:alf.io,代碼行數:12,代碼來源:Initializer.java

示例4: initialize

import org.springframework.web.context.ConfigurableWebApplicationContext; //導入方法依賴的package包/類
public void initialize(ConfigurableWebApplicationContext ctx) {
    ConfigurableEnvironment environment = ctx.getEnvironment();
    final String activeProfiles = ctx.getServletContext().getInitParameter("contxt.profile.initializer.active");
    final String[] profiles = activeProfiles.split(",");
    LOG.info("activating profiles {} from {}", profiles, activeProfiles);
    environment.setActiveProfiles(profiles);
}
 
開發者ID:goldengekko,項目名稱:Meetr-Backend,代碼行數:8,代碼來源:ContextProfileInitializer.java

示例5: 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


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