本文整理匯總了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();
}
示例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(), ","));
}
示例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;
}
示例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);
}
示例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();
}