Add BootstrapRegisty support for config data

Expose the `BootstrapRegisty` to both `ConfigDataLocationResolver` and
`ConfigDataLoader` implementations. The registry is exposed via the
context interfaces and may be used to reuse instances that are expensive
to create. It may also be used to ultimately register beans with the
`ApplicationContext`.

Closes gh-22956
This commit is contained in:
Phillip Webb
2020-08-20 17:26:01 -07:00
parent 2260657781
commit d123c924a0
26 changed files with 491 additions and 113 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.boot.test.context;
import org.springframework.boot.context.config.ConfigData;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.env.DefaultBootstrapRegisty;
import org.springframework.boot.env.DefaultPropertiesPropertySource;
import org.springframework.boot.env.RandomValuePropertySource;
import org.springframework.context.ApplicationContextInitializer;
@@ -41,7 +42,9 @@ public class ConfigDataApplicationContextInitializer
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment environment = applicationContext.getEnvironment();
RandomValuePropertySource.addToEnvironment(environment);
ConfigDataEnvironmentPostProcessor.applyTo(environment, applicationContext);
DefaultBootstrapRegisty bootstrapRegistry = new DefaultBootstrapRegisty();
ConfigDataEnvironmentPostProcessor.applyTo(environment, applicationContext, bootstrapRegistry);
bootstrapRegistry.applicationContextPrepared(applicationContext);
DefaultPropertiesPropertySource.moveToEnd(environment);
}