diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoader.java
index 22e5d3a754..eaea00ca3a 100644
--- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoader.java
+++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-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.
@@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.ConfigurableBootstrapContext;
+import org.springframework.boot.logging.DeferredLogFactory;
/**
* Strategy class that can be used used to load {@link ConfigData} for a given
@@ -30,7 +31,8 @@ import org.springframework.boot.ConfigurableBootstrapContext;
* {@code spring.factories} entries. The following constructor parameter types are
* supported:
*
- * - {@link Log} - if the resolver needs deferred logging
+ * - {@link Log} or {@link DeferredLogFactory} - if the loader needs deferred
+ * logging
* - {@link ConfigurableBootstrapContext} - A bootstrap context that can be used to
* store objects that may be expensive to create, or need to be shared
* ({@link BootstrapContext} or {@link BootstrapRegistry} may also be used).
diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java
index d2c1c681e2..86ef04d5f2 100644
--- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java
+++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLoaders.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-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.
@@ -68,6 +68,7 @@ class ConfigDataLoaders {
Instantiator> instantiator = new Instantiator<>(ConfigDataLoader.class,
(availableParameters) -> {
availableParameters.add(Log.class, logFactory::getLog);
+ availableParameters.add(DeferredLogFactory.class, logFactory);
availableParameters.add(ConfigurableBootstrapContext.class, bootstrapContext);
availableParameters.add(BootstrapContext.class, bootstrapContext);
availableParameters.add(BootstrapRegistry.class, bootstrapContext);
diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolver.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolver.java
index f51ae7c50c..08bfa76821 100644
--- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolver.java
+++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolver.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-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.
@@ -25,6 +25,7 @@ import org.springframework.boot.BootstrapContext;
import org.springframework.boot.BootstrapRegistry;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.context.properties.bind.Binder;
+import org.springframework.boot.logging.DeferredLogFactory;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.Environment;
@@ -36,7 +37,8 @@ import org.springframework.core.io.ResourceLoader;
* {@code spring.factories} entries. The following constructor parameter types are
* supported:
*
- * - {@link Log} - if the resolver needs deferred logging
+ * - {@link Log} or {@link DeferredLogFactory} - if the resolver needs deferred
+ * logging
* - {@link Binder} - if the resolver needs to obtain values from the initial
* {@link Environment}
* - {@link ResourceLoader} - if the resolver needs a resource loader
diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java
index 3951c07c75..60f5ce9269 100644
--- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java
+++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java
@@ -70,6 +70,7 @@ class ConfigDataLocationResolvers {
Instantiator> instantiator = new Instantiator<>(ConfigDataLocationResolver.class,
(availableParameters) -> {
availableParameters.add(Log.class, logFactory::getLog);
+ availableParameters.add(DeferredLogFactory.class, logFactory);
availableParameters.add(Binder.class, binder);
availableParameters.add(ResourceLoader.class, resourceLoader);
availableParameters.add(ConfigurableBootstrapContext.class, bootstrapContext);
diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java
index ca0aa74b38..df7b9655ba 100644
--- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java
+++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLoadersTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-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.
@@ -57,6 +57,20 @@ class ConfigDataLoadersTests {
Arrays.asList(LoggingConfigDataLoader.class.getName()));
}
+ @Test
+ void createWhenLoaderHasDeferredLogFactoryParameterInjectsDeferredLogFactory() {
+ ConfigDataLoaders loaders = new ConfigDataLoaders(this.logFactory, this.bootstrapContext,
+ Arrays.asList(DeferredLogFactoryConfigDataLoader.class.getName()));
+ assertThat(loaders).extracting("loaders").asList()
+ .satisfies(this::containsValidDeferredLogFactoryConfigDataLoader);
+ }
+
+ private void containsValidDeferredLogFactoryConfigDataLoader(List> list) {
+ assertThat(list).hasSize(1);
+ DeferredLogFactoryConfigDataLoader loader = (DeferredLogFactoryConfigDataLoader) list.get(0);
+ assertThat(loader.getLogFactory()).isSameAs(this.logFactory);
+ }
+
@Test
void createWhenLoaderHasBootstrapParametersInjectsBootstrapContext() {
new ConfigDataLoaders(this.logFactory, this.bootstrapContext,
@@ -144,6 +158,26 @@ class ConfigDataLoadersTests {
}
+ static class DeferredLogFactoryConfigDataLoader implements ConfigDataLoader {
+
+ private final DeferredLogFactory logFactory;
+
+ DeferredLogFactoryConfigDataLoader(DeferredLogFactory logFactory) {
+ assertThat(logFactory).isNotNull();
+ this.logFactory = logFactory;
+ }
+
+ @Override
+ public ConfigData load(ConfigDataLoaderContext context, ConfigDataResource resource) throws IOException {
+ throw new AssertionError("Unexpected call");
+ }
+
+ DeferredLogFactory getLogFactory() {
+ return this.logFactory;
+ }
+
+ }
+
static class BootstrappingConfigDataLoader implements ConfigDataLoader {
BootstrappingConfigDataLoader(ConfigurableBootstrapContext configurableBootstrapContext,
diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
index 784e723c15..abc12408f4 100644
--- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
+++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2012-2020 the original author or authors.
+ * Copyright 2012-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.
@@ -23,6 +23,7 @@ import java.util.Collections;
import java.util.List;
import java.util.function.Supplier;
+import org.apache.commons.logging.Log;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
@@ -68,6 +69,17 @@ class ConfigDataLocationResolversTests {
private ResourceLoader resourceLoader = new DefaultResourceLoader();
+ @Test
+ void createWhenInjectingLogAndDeferredLogFactoryCreatesResolver() {
+ ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext,
+ this.binder, this.resourceLoader, Collections.singletonList(TestLogResolver.class.getName()));
+ assertThat(resolvers.getResolvers()).hasSize(1);
+ assertThat(resolvers.getResolvers().get(0)).isExactlyInstanceOf(TestLogResolver.class);
+ TestLogResolver resolver = (TestLogResolver) resolvers.getResolvers().get(0);
+ assertThat(resolver.getDeferredLogFactory()).isSameAs(this.logFactory);
+ assertThat(resolver.getLog()).isNotNull();
+ }
+
@Test
void createWhenInjectingBinderCreatesResolver() {
ConfigDataLocationResolvers resolvers = new ConfigDataLocationResolvers(this.logFactory, this.bootstrapContext,
@@ -180,6 +192,27 @@ class ConfigDataLocationResolversTests {
}
+ static class TestLogResolver extends TestResolver {
+
+ private final DeferredLogFactory deferredLogFactory;
+
+ private final Log log;
+
+ TestLogResolver(DeferredLogFactory deferredLogFactory, Log log) {
+ this.deferredLogFactory = deferredLogFactory;
+ this.log = log;
+ }
+
+ DeferredLogFactory getDeferredLogFactory() {
+ return this.deferredLogFactory;
+ }
+
+ Log getLog() {
+ return this.log;
+ }
+
+ }
+
static class TestBoundResolver extends TestResolver {
private final Binder binder;