Add ConfigDataEnvironmentPostProcessor.applyTo

Add static methods to `ConfigDataEnvironmentPostProcessor` so that
post-processing can be applied to `Environment` instances directly.

Closes gh-22601
This commit is contained in:
Phillip Webb
2020-08-06 14:34:39 -07:00
parent f7f4ff0ac9
commit f8c8b65cbf
3 changed files with 52 additions and 18 deletions

View File

@@ -16,8 +16,6 @@
package org.springframework.boot.test.context;
import java.util.function.Supplier;
import org.springframework.boot.context.config.ConfigData;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.env.DefaultPropertiesPropertySource;
@@ -25,7 +23,6 @@ import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.test.context.ContextConfiguration;
/**
@@ -44,20 +41,8 @@ public class ConfigDataApplicationContextInitializer
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
RandomValuePropertySource.addToEnvironment(environment);
new ConfigDataProcessor().addPropertySources(environment, applicationContext);
ConfigDataEnvironmentPostProcessor.applyTo(environment, applicationContext);
DefaultPropertiesPropertySource.moveToEnd(environment);
}
private static class ConfigDataProcessor extends ConfigDataEnvironmentPostProcessor {
ConfigDataProcessor() {
super(Supplier::get);
}
void addPropertySources(ConfigurableEnvironment environment, ResourceLoader resourceLoader) {
addPropertySources(environment, resourceLoader, null);
}
}
}