Merge branch '3.0.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,8 +18,10 @@ package org.springframework.cloud.config.server.bootstrap;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
@@ -43,10 +45,15 @@ import org.springframework.core.env.PropertySource;
|
||||
* This listener is only to prevent it from using HTTP to contact itself.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Ryan Baxter
|
||||
*
|
||||
*/
|
||||
// TODO We changed this class from an ApplicationListener to an EnvironmentPostProcessor
|
||||
// but did not change the class name to avoid breaking anyone in a minor release.
|
||||
// In the next major it will be safe to change the class name and remove the
|
||||
// ApplicationListener interface.
|
||||
public class ConfigServerBootstrapApplicationListener
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, Ordered {
|
||||
implements ApplicationListener<ApplicationEnvironmentPreparedEvent>, EnvironmentPostProcessor, Ordered {
|
||||
|
||||
/**
|
||||
* Default order of the bootstrap application listener.
|
||||
@@ -58,6 +65,15 @@ public class ConfigServerBootstrapApplicationListener
|
||||
private PropertySource<?> propertySource = new MapPropertySource("configServerClient",
|
||||
Collections.<String, Object>singletonMap("spring.cloud.config.enabled", "false"));
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
if (!environment.resolvePlaceholders("${spring.cloud.config.enabled:false}").equalsIgnoreCase("true")) {
|
||||
if (!environment.getPropertySources().contains(this.propertySource.getName())) {
|
||||
environment.getPropertySources().addLast(this.propertySource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return this.order;
|
||||
@@ -69,12 +85,7 @@ public class ConfigServerBootstrapApplicationListener
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
|
||||
ConfigurableEnvironment environment = event.getEnvironment();
|
||||
if (!environment.resolvePlaceholders("${spring.cloud.config.enabled:false}").equalsIgnoreCase("true")) {
|
||||
if (!environment.getPropertySources().contains(this.propertySource.getName())) {
|
||||
environment.getPropertySources().addLast(this.propertySource);
|
||||
}
|
||||
}
|
||||
postProcessEnvironment(event.getEnvironment(), event.getSpringApplication());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapConfiguration,\
|
||||
org.springframework.cloud.config.server.config.EncryptionAutoConfiguration
|
||||
# Application listeners
|
||||
org.springframework.context.ApplicationListener=\
|
||||
|
||||
# Environment PostProcessor
|
||||
org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
org.springframework.cloud.config.server.bootstrap.ConfigServerBootstrapApplicationListener
|
||||
|
||||
# Autoconfiguration
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.config.server.config.ConfigServerAutoConfiguration,\
|
||||
|
||||
Reference in New Issue
Block a user