Skip to content

ManagementContextAutoConfiguration adds a property source that degrades binding performance #45968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.origin.Origin;
import org.springframework.boot.origin.OriginLookup;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.EnumerablePropertySource;
import org.springframework.core.env.Environment;
import org.springframework.core.env.PropertySource;
import org.springframework.util.Assert;

/**
Expand Down Expand Up @@ -84,17 +86,7 @@ private void verifyAddressConfiguration() {
* @param environment the environment
*/
private void addLocalManagementPortPropertyAlias(ConfigurableEnvironment environment) {
environment.getPropertySources().addLast(new PropertySource<>("Management Server") {

@Override
public Object getProperty(String name) {
if ("local.management.port".equals(name)) {
return environment.getProperty("local.server.port");
}
return null;
}

});
environment.getPropertySources().addLast(new LocalManagementPortPropertySource(environment));
}

@Configuration(proxyBeanMethods = false)
Expand All @@ -117,4 +109,40 @@ static ChildManagementContextInitializer childManagementContextInitializer(

}

static class LocalManagementPortPropertySource extends EnumerablePropertySource<Object>
implements OriginLookup<String> {

private static final String[] PROPERTIES = { "local.management.port" };

private final ConfigurableEnvironment environment;

LocalManagementPortPropertySource(ConfigurableEnvironment environment) {
super("Management Server");
this.environment = environment;
}

@Override
public String[] getPropertyNames() {
return PROPERTIES;
}

@Override
public Object getProperty(String name) {
if ("local.management.port".equals(name)) {
return this.environment.getProperty("local.server.port");
}
return null;
}

@Override
public Origin getOrigin(String key) {
return null;
}

@Override
public boolean isImmutable() {
return true;
}
}

}