Skip to content

Commit 2be5ffd

Browse files
committed
Remove constants from CloudFoundryVcapEnvironmentPostProcessor
This commit removes the VCAP_APPLICATION, VCAP_SERVICES, and VCAP_PROPERTY_SOURCE_NAME constants from the CloudFoundryVcapEnvironmentPostProcessor class, replacing them with string literals. This change simplifies the code and aligns with the team's decision to avoid using constants in this context. Signed-off-by: wonyongg <[email protected]>
1 parent 139436e commit 2be5ffd

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudFoundryVcapEnvironmentPostProcessor.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,6 @@
9191
*/
9292
public class CloudFoundryVcapEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered {
9393

94-
private static final String VCAP_APPLICATION = "VCAP_APPLICATION";
95-
96-
private static final String VCAP_SERVICES = "VCAP_SERVICES";
97-
9894
private final Log logger;
9995

10096
// Before ConfigDataEnvironmentPostProcessor so values there can use these
@@ -126,12 +122,12 @@ public void postProcessEnvironment(ConfigurableEnvironment environment, SpringAp
126122
addWithPrefix(properties, getPropertiesFromApplication(environment, jsonParser), "vcap.application.");
127123
addWithPrefix(properties, getPropertiesFromServices(environment, jsonParser), "vcap.services.");
128124
MutablePropertySources propertySources = environment.getPropertySources();
125+
PropertiesPropertySource vcapSource = new PropertiesPropertySource("vcap", properties);
129126
if (propertySources.contains(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
130-
propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
131-
new PropertiesPropertySource("vcap", properties));
127+
propertySources.addAfter(CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME, vcapSource);
132128
}
133129
else {
134-
propertySources.addFirst(new PropertiesPropertySource("vcap", properties));
130+
propertySources.addFirst(vcapSource);
135131
}
136132
}
137133
}
@@ -146,7 +142,7 @@ private void addWithPrefix(Properties properties, Properties other, String prefi
146142
private Properties getPropertiesFromApplication(Environment environment, JsonParser parser) {
147143
Properties properties = new Properties();
148144
try {
149-
String property = environment.getProperty(VCAP_APPLICATION, "{}");
145+
String property = environment.getProperty("VCAP_APPLICATION", "{}");
150146
Map<String, Object> map = parser.parseMap(property);
151147
extractPropertiesFromApplication(properties, map);
152148
}
@@ -159,7 +155,7 @@ private Properties getPropertiesFromApplication(Environment environment, JsonPar
159155
private Properties getPropertiesFromServices(Environment environment, JsonParser parser) {
160156
Properties properties = new Properties();
161157
try {
162-
String property = environment.getProperty(VCAP_SERVICES, "{}");
158+
String property = environment.getProperty("VCAP_SERVICES", "{}");
163159
Map<String, Object> map = parser.parseMap(property);
164160
extractPropertiesFromServices(properties, map);
165161
}

0 commit comments

Comments
 (0)