Make LogCorrelationPropertySource an EnumerablePropertySource
Change `LogCorrelationPropertySource` to an `EnumerablePropertySource` to reduce the likelihood of `Binder` errors. Closes gh-38349
This commit is contained in:
parent
ba56953ea5
commit
80210e93d3
|
|
@ -20,6 +20,7 @@ import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||||
import org.springframework.boot.logging.LoggingSystem;
|
import org.springframework.boot.logging.LoggingSystem;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.EnumerablePropertySource;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
|
|
@ -45,7 +46,7 @@ class LogCorrelationEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||||
/**
|
/**
|
||||||
* Log correlation {@link PropertySource}.
|
* Log correlation {@link PropertySource}.
|
||||||
*/
|
*/
|
||||||
private static class LogCorrelationPropertySource extends PropertySource<Object> {
|
private static class LogCorrelationPropertySource extends EnumerablePropertySource<Object> {
|
||||||
|
|
||||||
private static final String NAME = "logCorrelation";
|
private static final String NAME = "logCorrelation";
|
||||||
|
|
||||||
|
|
@ -56,6 +57,11 @@ class LogCorrelationEnvironmentPostProcessor implements EnvironmentPostProcessor
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] getPropertyNames() {
|
||||||
|
return new String[] { LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY };
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getProperty(String name) {
|
public Object getProperty(String name) {
|
||||||
if (name.equals(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY)) {
|
if (name.equals(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY)) {
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ import org.springframework.boot.logging.LoggingSystem;
|
||||||
import org.springframework.boot.test.util.TestPropertyValues;
|
import org.springframework.boot.test.util.TestPropertyValues;
|
||||||
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
|
||||||
import org.springframework.core.env.ConfigurableEnvironment;
|
import org.springframework.core.env.ConfigurableEnvironment;
|
||||||
|
import org.springframework.core.env.EnumerablePropertySource;
|
||||||
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.core.env.StandardEnvironment;
|
import org.springframework.core.env.StandardEnvironment;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
@ -64,4 +66,13 @@ class LogCorrelationEnvironmentPostProcessorTests {
|
||||||
.isFalse();
|
.isFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void postProcessEnvironmentAddsEnumerablePropertySource() {
|
||||||
|
this.postProcessor.postProcessEnvironment(this.environment, this.application);
|
||||||
|
PropertySource<?> propertySource = this.environment.getPropertySources().get("logCorrelation");
|
||||||
|
assertThat(propertySource).isInstanceOf(EnumerablePropertySource.class);
|
||||||
|
assertThat(((EnumerablePropertySource<?>) propertySource).getPropertyNames())
|
||||||
|
.containsExactly(LoggingSystem.EXPECT_CORRELATION_ID_PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue