Skip to content

Commit ad0f08f

Browse files
committed
Polish 'Improve binding performance of 'local.management.port' property source'
See gh-45968
1 parent d5464a4 commit ad0f08f

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/web/server/ManagementContextAutoConfiguration.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.boot.actuate.autoconfigure.web.server;
1818

19+
import java.util.Map;
20+
1921
import org.springframework.beans.factory.SmartInitializingSingleton;
2022
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextFactory;
2123
import org.springframework.boot.actuate.autoconfigure.web.ManagementContextType;
@@ -109,29 +111,33 @@ static ChildManagementContextInitializer childManagementContextInitializer(
109111

110112
}
111113

114+
/**
115+
* {@link EnumerablePropertySource} providing {@code local.management.port} support.
116+
*/
112117
static class LocalManagementPortPropertySource extends EnumerablePropertySource<Object>
113118
implements OriginLookup<String> {
114119

115-
private static final String[] PROPERTIES = { "local.management.port" };
120+
private static final Map<String, String> PROPERTY_MAPPINGS = Map.of("local.management.port",
121+
"local.server.port");
122+
123+
private static final String[] PROPERTY_NAMES = PROPERTY_MAPPINGS.keySet().toArray(String[]::new);
116124

117-
private final ConfigurableEnvironment environment;
125+
private final Environment environment;
118126

119-
LocalManagementPortPropertySource(ConfigurableEnvironment environment) {
127+
LocalManagementPortPropertySource(Environment environment) {
120128
super("Management Server");
121129
this.environment = environment;
122130
}
123131

124132
@Override
125133
public String[] getPropertyNames() {
126-
return PROPERTIES;
134+
return PROPERTY_NAMES;
127135
}
128136

129137
@Override
130138
public Object getProperty(String name) {
131-
if ("local.management.port".equals(name)) {
132-
return this.environment.getProperty("local.server.port");
133-
}
134-
return null;
139+
String mapped = PROPERTY_MAPPINGS.get(name);
140+
return (mapped != null) ? this.environment.getProperty(mapped) : null;
135141
}
136142

137143
@Override
@@ -143,6 +149,7 @@ public Origin getOrigin(String key) {
143149
public boolean isImmutable() {
144150
return true;
145151
}
152+
146153
}
147154

148155
}

0 commit comments

Comments
 (0)