|
35 | 35 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
36 | 36 | import org.springframework.boot.context.properties.bind.Bindable.BindRestriction;
|
37 | 37 | import org.springframework.boot.context.properties.source.ConfigurationProperty;
|
| 38 | +import org.springframework.boot.context.properties.source.ConfigurationPropertyCaching; |
38 | 39 | import org.springframework.boot.context.properties.source.ConfigurationPropertyName;
|
39 | 40 | import org.springframework.boot.context.properties.source.ConfigurationPropertySource;
|
40 | 41 | import org.springframework.boot.context.properties.source.ConfigurationPropertySources;
|
@@ -69,6 +70,8 @@ public class Binder {
|
69 | 70 |
|
70 | 71 | private final Map<BindMethod, List<DataObjectBinder>> dataObjectBinders;
|
71 | 72 |
|
| 73 | + private ConfigurationPropertyCaching configurationPropertyCaching; |
| 74 | + |
72 | 75 | /**
|
73 | 76 | * Create a new {@link Binder} instance for the specified sources. A
|
74 | 77 | * {@link DefaultFormattingConversionService} will be used for all conversion.
|
@@ -189,6 +192,7 @@ public Binder(Iterable<ConfigurationPropertySource> sources, PlaceholdersResolve
|
189 | 192 | Assert.notNull(source, "'sources' must not contain null elements");
|
190 | 193 | }
|
191 | 194 | this.sources = sources;
|
| 195 | + this.configurationPropertyCaching = ConfigurationPropertyCaching.get(sources); |
192 | 196 | this.placeholdersResolver = (placeholdersResolver != null) ? placeholdersResolver : PlaceholdersResolver.NONE;
|
193 | 197 | this.bindConverter = BindConverter.get(conversionServices, propertyEditorInitializer);
|
194 | 198 | this.defaultBindHandler = (defaultBindHandler != null) ? defaultBindHandler : BindHandler.DEFAULT;
|
@@ -341,17 +345,19 @@ private <T> T bind(ConfigurationPropertyName name, Bindable<T> target, BindHandl
|
341 | 345 |
|
342 | 346 | private <T> T bind(ConfigurationPropertyName name, Bindable<T> target, BindHandler handler, Context context,
|
343 | 347 | boolean allowRecursiveBinding, boolean create) {
|
344 |
| - try { |
345 |
| - Bindable<T> replacementTarget = handler.onStart(name, target, context); |
346 |
| - if (replacementTarget == null) { |
347 |
| - return handleBindResult(name, target, handler, context, null, create); |
| 348 | + try (ConfigurationPropertyCaching.CacheOverride cacheOverride = this.configurationPropertyCaching.override()) { |
| 349 | + try { |
| 350 | + Bindable<T> replacementTarget = handler.onStart(name, target, context); |
| 351 | + if (replacementTarget == null) { |
| 352 | + return handleBindResult(name, target, handler, context, null, create); |
| 353 | + } |
| 354 | + target = replacementTarget; |
| 355 | + Object bound = bindObject(name, target, handler, context, allowRecursiveBinding); |
| 356 | + return handleBindResult(name, target, handler, context, bound, create); |
| 357 | + } |
| 358 | + catch (Exception ex) { |
| 359 | + return handleBindError(name, target, handler, context, ex); |
348 | 360 | }
|
349 |
| - target = replacementTarget; |
350 |
| - Object bound = bindObject(name, target, handler, context, allowRecursiveBinding); |
351 |
| - return handleBindResult(name, target, handler, context, bound, create); |
352 |
| - } |
353 |
| - catch (Exception ex) { |
354 |
| - return handleBindError(name, target, handler, context, ex); |
355 | 361 | }
|
356 | 362 | }
|
357 | 363 |
|
|
0 commit comments