1616
1717package org .springframework .boot .actuate .autoconfigure .web .server ;
1818
19+ import java .util .Map ;
20+
1921import org .springframework .beans .factory .SmartInitializingSingleton ;
2022import org .springframework .boot .actuate .autoconfigure .web .ManagementContextFactory ;
2123import 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