mirror of
https://github.com/spring-projects/spring-boot.git
synced 2024-08-29 03:06:45 +08:00
parent
0fbb1f7890
commit
5ff4a961b1
@ -55,7 +55,7 @@ public class RSocketPortInfoApplicationContextInitializer
|
||||
|
||||
private static final String PROPERTY_NAME = "local.rsocket.server.port";
|
||||
|
||||
private static final String SERVER_PORTS = "server.ports";
|
||||
private static final String PROPERTY_SOURCE_NAME = "server.ports";
|
||||
|
||||
private final ConfigurableApplicationContext applicationContext;
|
||||
|
||||
@ -81,9 +81,9 @@ public class RSocketPortInfoApplicationContextInitializer
|
||||
|
||||
private void setPortProperty(ConfigurableEnvironment environment, int port) {
|
||||
MutablePropertySources sources = environment.getPropertySources();
|
||||
PropertySource<?> source = sources.get(SERVER_PORTS);
|
||||
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
|
||||
if (source == null) {
|
||||
source = new MapPropertySource(SERVER_PORTS, new HashMap<>());
|
||||
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
|
||||
sources.addFirst(source);
|
||||
}
|
||||
setPortProperty(port, source);
|
||||
|
@ -52,6 +52,8 @@ import org.springframework.util.StringUtils;
|
||||
public class ServerPortInfoApplicationContextInitializer implements
|
||||
ApplicationContextInitializer<ConfigurableApplicationContext>, ApplicationListener<WebServerInitializedEvent> {
|
||||
|
||||
private static final String PROPERTY_SOURCE_NAME = "server.ports";
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.addApplicationListener(this);
|
||||
@ -80,9 +82,9 @@ public class ServerPortInfoApplicationContextInitializer implements
|
||||
@SuppressWarnings("unchecked")
|
||||
private void setPortProperty(ConfigurableEnvironment environment, String propertyName, int port) {
|
||||
MutablePropertySources sources = environment.getPropertySources();
|
||||
PropertySource<?> source = sources.get("server.ports");
|
||||
PropertySource<?> source = sources.get(PROPERTY_SOURCE_NAME);
|
||||
if (source == null) {
|
||||
source = new MapPropertySource("server.ports", new HashMap<>());
|
||||
source = new MapPropertySource(PROPERTY_SOURCE_NAME, new HashMap<>());
|
||||
sources.addFirst(source);
|
||||
}
|
||||
((Map<String, Object>) source.getSource()).put(propertyName, port);
|
||||
|
Loading…
Reference in New Issue
Block a user