Provide ConfigFileApplicationListener replacement

Deprecate `ConfigFileApplicationListener` and provide a replacement
mechanism that supports arbitrary config data imports.

This commit updates the following areas:

- Extract `EnvironmentPostProcessor` invocation logic from the
  `ConfigFileApplicationListener` to new dedicated listener. Also
  providing support for `Log` injection.

- Extract `RandomPropertySource` adding logic from the
  `ConfigFileApplicationListener` to a dedicated class.

- Migrate to the recently introduced `DefaultPropertiesPropertySource`
  class when moving the defaultProperties `PropertySource`

- Replace processing logic with a phased approach to ensure that
  profile enablement happens in a distinct phase and that profiles
  can no longer be activated on an ad-hoc basis.

- Provide a more predictable and logical import order for processing
  `application.properties` and `application.yml` files.

- Add support for a `spring.config.import` property which can be used
  to import additional config data. Also provide a pluggable API
  allowing third-parties to resolve and load locations themselves.

- Add `spring.config.activate.on-profile` support which replaces the
  existing `spring.profiles` property.

- Add `spring.config.activate.on-cloud-platform` support which allows
  a config data document to be active only on a given cloud platform.

- Support a `spring.config.use-legacy-processing` property allowing the
  previous processing logic to be used.

Closes gh-22497

Co-authored-by: Madhura Bhave <mbhave@vmware.com>
This commit is contained in:
Phillip Webb
2020-07-13 21:19:10 -07:00
parent 44f18362d3
commit 3352024b1c
96 changed files with 8130 additions and 168 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 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.
@@ -25,13 +25,14 @@ import org.springframework.boot.ResourceBanner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.context.config.AnsiOutputApplicationListener;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.context.config.ConfigDataEnvironmentPostProcessor;
import org.springframework.boot.context.logging.ClasspathLoggingApplicationListener;
import org.springframework.boot.context.logging.LoggingApplicationListener;
import org.springframework.boot.devtools.remote.client.RemoteClientConfiguration;
import org.springframework.boot.devtools.restart.RestartInitializer;
import org.springframework.boot.devtools.restart.RestartScopeInitializer;
import org.springframework.boot.devtools.restart.Restarter;
import org.springframework.boot.env.EnvironmentPostProcessorApplicationListener;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ApplicationListener;
import org.springframework.core.io.ClassPathResource;
@@ -71,7 +72,7 @@ public final class RemoteSpringApplication {
private Collection<ApplicationListener<?>> getListeners() {
List<ApplicationListener<?>> listeners = new ArrayList<>();
listeners.add(new AnsiOutputApplicationListener());
listeners.add(new ConfigFileApplicationListener());
listeners.add(new EnvironmentPostProcessorApplicationListener(ConfigDataEnvironmentPostProcessor.class));
listeners.add(new ClasspathLoggingApplicationListener());
listeners.add(new LoggingApplicationListener());
listeners.add(new RemoteUrlPropertyExtractor());