From 9281e2a410bb493d59448f9c3249af0c3a34ed46 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 25 Jun 2018 17:35:30 +0100 Subject: [PATCH] Avoid creating JsonParser for VCAP_* parsing when running outside CF Closes gh-13437 --- ...oudFoundryVcapEnvironmentPostProcessor.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java index 5a7afea4aa..4425eb29ba 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java @@ -101,8 +101,6 @@ public class CloudFoundryVcapEnvironmentPostProcessor // Before ConfigFileApplicationListener so values there can use these ones private int order = ConfigFileApplicationListener.DEFAULT_ORDER - 1; - private final JsonParser parser = JsonParserFactory.getJsonParser(); - public void setOrder(int order) { this.order = order; } @@ -117,9 +115,11 @@ public class CloudFoundryVcapEnvironmentPostProcessor SpringApplication application) { if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) { Properties properties = new Properties(); - addWithPrefix(properties, getPropertiesFromApplication(environment), + JsonParser jsonParser = JsonParserFactory.getJsonParser(); + addWithPrefix(properties, + getPropertiesFromApplication(environment, jsonParser), "vcap.application."); - addWithPrefix(properties, getPropertiesFromServices(environment), + addWithPrefix(properties, getPropertiesFromServices(environment, jsonParser), "vcap.services."); MutablePropertySources propertySources = environment.getPropertySources(); if (propertySources.contains( @@ -142,11 +142,12 @@ public class CloudFoundryVcapEnvironmentPostProcessor } } - private Properties getPropertiesFromApplication(Environment environment) { + private Properties getPropertiesFromApplication(Environment environment, + JsonParser parser) { Properties properties = new Properties(); try { String property = environment.getProperty(VCAP_APPLICATION, "{}"); - Map map = this.parser.parseMap(property); + Map map = parser.parseMap(property); extractPropertiesFromApplication(properties, map); } catch (Exception ex) { @@ -155,11 +156,12 @@ public class CloudFoundryVcapEnvironmentPostProcessor return properties; } - private Properties getPropertiesFromServices(Environment environment) { + private Properties getPropertiesFromServices(Environment environment, + JsonParser parser) { Properties properties = new Properties(); try { String property = environment.getProperty(VCAP_SERVICES, "{}"); - Map map = this.parser.parseMap(property); + Map map = parser.parseMap(property); extractPropertiesFromServices(properties, map); } catch (Exception ex) {