From 975a3aacd62ae4d09adbe5fbc6824f78c4cb4ce8 Mon Sep 17 00:00:00 2001 From: SangYong Date: Sun, 13 Oct 2024 14:43:29 +0900 Subject: [PATCH] Polish SpringApplication See gh-42606 --- .../springframework/boot/SpringApplication.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) 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 e2b5e731ce..e1d311ff76 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,13 @@ public class SpringApplication { } 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()); + environmentType = ApplicationContextFactory.DEFAULT.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 +470,10 @@ public class SpringApplication { if (this.environment != null) { return this.environment; } - ConfigurableEnvironment environment = this.applicationContextFactory - .createEnvironment(this.properties.getWebApplicationType()); + WebApplicationType webApplicationType = this.properties.getWebApplicationType(); + ConfigurableEnvironment environment = this.applicationContextFactory.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(); }