Rework ConfigurationPropertySources
Rework the ConfigurationPropertySources and related adapter classes to help with performance. The ConfigurationPropertySources class now only monitors for updates when `.attach` is used. The `.get` methods now return the adapted version, but no longer checks to see if sources have been added or removed on each call. This commit also fixes a few caching issues and makes both the `PropertyMapper` implementations true static singletons. See gh-9000
This commit is contained in:
@@ -25,7 +25,6 @@ import org.springframework.boot.context.properties.bind.Bindable;
|
||||
import org.springframework.boot.context.properties.bind.Binder;
|
||||
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
||||
import org.springframework.boot.info.InfoProperties;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -93,9 +92,7 @@ public abstract class InfoPropertiesInfoContributor<T extends InfoProperties>
|
||||
* @return the raw content
|
||||
*/
|
||||
protected Map<String, Object> extractContent(PropertySource<?> propertySource) {
|
||||
MutablePropertySources sources = new MutablePropertySources();
|
||||
sources.addFirst(propertySource);
|
||||
return new Binder(ConfigurationPropertySources.get(sources))
|
||||
return new Binder(ConfigurationPropertySources.from(propertySource))
|
||||
.bind("", STRING_OBJECT_MAP).orElseGet(LinkedHashMap::new);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@@ -320,9 +321,8 @@ public class EndpointAutoConfigurationTests {
|
||||
if (!location.exists()) {
|
||||
return;
|
||||
}
|
||||
MapConfigurationPropertySource source = new MapConfigurationPropertySource(
|
||||
PropertiesLoaderUtils.loadProperties(location));
|
||||
new Binder(source).bind("info",
|
||||
Properties properties = PropertiesLoaderUtils.loadProperties(location);
|
||||
new Binder(new MapConfigurationPropertySource(properties)).bind("info",
|
||||
Bindable.of(STRING_OBJECT_MAP).withExistingValue(this.content));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user