Java Code Examples for org.springframework.web.context.ConfigurableWebApplicationContext#getEnvironment()
The following examples show how to use
org.springframework.web.context.ConfigurableWebApplicationContext#getEnvironment() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FrameworkServlet.java From spring-analysis-note with MIT License | 5 votes |
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... 生成默认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); // 遍历 ApplicationContextInitializer,执行 initialize 方法 applyInitializers(wac); // 关键的刷新,加载配置文件及整合 parent 到 wac wac.refresh(); }
Example 2
Source File: FrameworkServlet.java From java-technology-stack with MIT License | 5 votes |
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(); }
Example 3
Source File: FrameworkServlet.java From lams with GNU General Public License v2.0 | 5 votes |
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(); }
Example 4
Source File: FrameworkServlet.java From spring4-understanding with Apache License 2.0 | 5 votes |
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(); }
Example 5
Source File: ProfileInitializer.java From the-app with Apache License 2.0 | 5 votes |
@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(), ",")); }
Example 6
Source File: ProfileInitializer.java From AppStash with Apache License 2.0 | 5 votes |
@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(), ",")); }
Example 7
Source File: Initializer.java From alf.io with GNU General Public License v3.0 | 5 votes |
@Override protected WebApplicationContext createRootApplicationContext() { ConfigurableWebApplicationContext ctx = ((ConfigurableWebApplicationContext) super.createRootApplicationContext()); Objects.requireNonNull(ctx, "Something really bad is happening..."); this.environment = ctx.getEnvironment(); return ctx; }