diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index e2b5e731ce62..20d8da4e32eb 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -365,16 +365,14 @@ private ConfigurableEnvironment prepareEnvironment(SpringApplicationRunListeners } private Class deduceEnvironmentClass() { + WebApplicationType webApplicationType = this.properties.getWebApplicationType(); Class environmentType = this.applicationContextFactory - .getEnvironmentType(this.properties.getWebApplicationType()); + .getEnvironmentType(webApplicationType); if (environmentType == null && this.applicationContextFactory != ApplicationContextFactory.DEFAULT) { environmentType = ApplicationContextFactory.DEFAULT - .getEnvironmentType(this.properties.getWebApplicationType()); + .getEnvironmentType(webApplicationType); } - if (environmentType == null) { - return ApplicationEnvironment.class; - } - return environmentType; + return (environmentType != null) ? environmentType : ApplicationEnvironment.class; } private void prepareContext(DefaultBootstrapContext bootstrapContext, ConfigurableApplicationContext context, @@ -473,10 +471,11 @@ private ConfigurableEnvironment getOrCreateEnvironment() { if (this.environment != null) { return this.environment; } + WebApplicationType webApplicationType = this.properties.getWebApplicationType(); ConfigurableEnvironment environment = this.applicationContextFactory - .createEnvironment(this.properties.getWebApplicationType()); + .createEnvironment(webApplicationType); if (environment == null && this.applicationContextFactory != ApplicationContextFactory.DEFAULT) { - environment = ApplicationContextFactory.DEFAULT.createEnvironment(this.properties.getWebApplicationType()); + environment = ApplicationContextFactory.DEFAULT.createEnvironment(webApplicationType); } return (environment != null) ? environment : new ApplicationEnvironment(); }