Passing Conversion service to boot Binder

This commit is contained in:
Vinicius Carvalho
2017-09-01 17:39:03 -04:00
committed by Soby Chacko
parent d317638bef
commit 24cf992301

View File

@@ -21,9 +21,11 @@ import java.util.Map;
import java.util.Set;
import org.springframework.beans.BeanUtils;
import org.springframework.core.convert.ConversionService;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.boot.context.properties.bind.PropertySourcesPlaceholdersResolver;
import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.util.Assert;
@@ -41,6 +43,7 @@ import org.springframework.util.Assert;
* @author Marius Bogoevici
* @author Ilayaperumal Gopinathan
* @author Janne Valkealahti
* @author Vinicius Carvalho
*/
public class EnvironmentEntryInitializingTreeMap<T> extends AbstractMap<String, T> {
@@ -81,7 +84,8 @@ public class EnvironmentEntryInitializingTreeMap<T> extends AbstractMap<String,
public T get(Object key) {
if (!this.delegate.containsKey(key) && key instanceof String) {
T entry = BeanUtils.instantiate(entryClass);
Binder.get(environment).bind(defaultsPrefix, Bindable.ofInstance(entry));
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(entry));
this.delegate.put((String) key, entry);
}
return this.delegate.get(key);
@@ -90,7 +94,8 @@ public class EnvironmentEntryInitializingTreeMap<T> extends AbstractMap<String,
@Override
public T put(String key, T value) {
// boot 2 call this first
Binder.get(environment).bind(defaultsPrefix, Bindable.ofInstance(value));
Binder binder = new Binder(ConfigurationPropertySources.get(environment),new PropertySourcesPlaceholdersResolver(environment),this.conversionService);
binder.bind(defaultsPrefix, Bindable.ofInstance(value));
return this.delegate.put(key, value);
}