Polish "Allow customer resolver and property sources"
See gh-26462
This commit is contained in:
@@ -129,8 +129,8 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
||||
* {@link #customizePropertySources(MutablePropertySources)} during
|
||||
* construction to allow subclasses to contribute or manipulate
|
||||
* {@link PropertySource} instances as appropriate.
|
||||
* @see #customizePropertySources(MutablePropertySources)
|
||||
* @since 5.3.4
|
||||
* @see #customizePropertySources(MutablePropertySources)
|
||||
*/
|
||||
protected AbstractEnvironment(MutablePropertySources propertySources) {
|
||||
this.propertySources = propertySources;
|
||||
@@ -142,17 +142,17 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
|
||||
/**
|
||||
* Factory method used to create the {@link ConfigurablePropertyResolver}
|
||||
* instance used by the Environment.
|
||||
* @see #getPropertyResolver()
|
||||
* @since 5.3.4
|
||||
* @see #getPropertyResolver()
|
||||
*/
|
||||
protected ConfigurablePropertyResolver createPropertyResolver(
|
||||
MutablePropertySources propertySources) {
|
||||
protected ConfigurablePropertyResolver createPropertyResolver(MutablePropertySources propertySources) {
|
||||
return new PropertySourcesPropertyResolver(propertySources);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link ConfigurablePropertyResolver} being used by the
|
||||
* {@link Environment}.
|
||||
* @since 5.3.4
|
||||
* @see #createPropertyResolver(MutablePropertySources)
|
||||
*/
|
||||
protected final ConfigurablePropertyResolver getPropertyResolver() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
||||
@@ -131,18 +131,15 @@ class CustomEnvironmentTests {
|
||||
|
||||
@Test
|
||||
public void withCustomMutablePropertySources() {
|
||||
class CustomMutablePropertySources extends MutablePropertySources {
|
||||
}
|
||||
class CustomMutablePropertySources extends MutablePropertySources {}
|
||||
MutablePropertySources propertySources = new CustomMutablePropertySources();
|
||||
ConfigurableEnvironment env = new AbstractEnvironment(propertySources) {
|
||||
};
|
||||
ConfigurableEnvironment env = new AbstractEnvironment(propertySources) {};
|
||||
assertThat(env.getPropertySources()).isInstanceOf(CustomMutablePropertySources.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void withCustomPropertyResolver() {
|
||||
class CustomPropertySourcesPropertyResolver extends PropertySourcesPropertyResolver {
|
||||
|
||||
public CustomPropertySourcesPropertyResolver(
|
||||
PropertySources propertySources) {
|
||||
super(propertySources);
|
||||
@@ -152,16 +149,13 @@ class CustomEnvironmentTests {
|
||||
public String getProperty(String key) {
|
||||
return super.getProperty(key)+"-test";
|
||||
}
|
||||
|
||||
}
|
||||
ConfigurableEnvironment env = new AbstractEnvironment() {
|
||||
|
||||
@Override
|
||||
protected ConfigurablePropertyResolver createPropertyResolver(
|
||||
MutablePropertySources propertySources) {
|
||||
return new CustomPropertySourcesPropertyResolver(propertySources);
|
||||
}
|
||||
|
||||
};
|
||||
Map<String, Object> values = new LinkedHashMap<>();
|
||||
values.put("spring", "framework");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
|
||||
Reference in New Issue
Block a user