29
29
import org .springframework .boot .context .properties .bind .Binder ;
30
30
import org .springframework .boot .context .properties .bind .PlaceholdersResolver ;
31
31
import org .springframework .boot .context .properties .source .ConfigurationPropertySource ;
32
+ import org .springframework .core .convert .ConversionService ;
32
33
import org .springframework .core .env .Environment ;
33
34
import org .springframework .core .env .PropertySource ;
34
35
import org .springframework .util .CollectionUtils ;
@@ -74,6 +75,8 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
74
75
75
76
private final Kind kind ;
76
77
78
+ private final ConversionService conversionService ;
79
+
77
80
/**
78
81
* Create a new {@link ConfigDataEnvironmentContributor} instance.
79
82
* @param kind the contributor kind
@@ -87,11 +90,13 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
87
90
* @param properties the config data properties or {@code null}
88
91
* @param configDataOptions any config data options that should apply
89
92
* @param children the children of this contributor at each {@link ImportPhase}
93
+ * @param conversionService the conversion service to use
90
94
*/
91
95
ConfigDataEnvironmentContributor (Kind kind , ConfigDataLocation location , ConfigDataResource resource ,
92
96
boolean fromProfileSpecificImport , PropertySource <?> propertySource ,
93
97
ConfigurationPropertySource configurationPropertySource , ConfigDataProperties properties ,
94
- ConfigData .Options configDataOptions , Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ) {
98
+ ConfigData .Options configDataOptions , Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ,
99
+ ConversionService conversionService ) {
95
100
this .kind = kind ;
96
101
this .location = location ;
97
102
this .resource = resource ;
@@ -101,6 +106,7 @@ class ConfigDataEnvironmentContributor implements Iterable<ConfigDataEnvironment
101
106
this .configurationPropertySource = configurationPropertySource ;
102
107
this .configDataOptions = (configDataOptions != null ) ? configDataOptions : ConfigData .Options .NONE ;
103
108
this .children = (children != null ) ? children : Collections .emptyMap ();
109
+ this .conversionService = conversionService ;
104
110
}
105
111
106
112
/**
@@ -171,7 +177,7 @@ boolean hasConfigDataOption(ConfigData.Option option) {
171
177
ConfigDataEnvironmentContributor withoutConfigDataOption (ConfigData .Option option ) {
172
178
return new ConfigDataEnvironmentContributor (this .kind , this .location , this .resource ,
173
179
this .fromProfileSpecificImport , this .propertySource , this .configurationPropertySource , this .properties ,
174
- this .configDataOptions .without (option ), this .children );
180
+ this .configDataOptions .without (option ), this .children , this . conversionService );
175
181
}
176
182
177
183
/**
@@ -235,15 +241,15 @@ ConfigDataEnvironmentContributor withBoundProperties(Iterable<ConfigDataEnvironm
235
241
ConfigDataActivationContext activationContext ) {
236
242
Iterable <ConfigurationPropertySource > sources = Collections .singleton (getConfigurationPropertySource ());
237
243
PlaceholdersResolver placeholdersResolver = new ConfigDataEnvironmentContributorPlaceholdersResolver (
238
- contributors , activationContext , this , true );
244
+ contributors , activationContext , this , true , this . conversionService );
239
245
Binder binder = new Binder (sources , placeholdersResolver , null , null , null );
240
246
ConfigDataProperties properties = ConfigDataProperties .get (binder );
241
247
if (properties != null && this .configDataOptions .contains (ConfigData .Option .IGNORE_IMPORTS )) {
242
248
properties = properties .withoutImports ();
243
249
}
244
250
return new ConfigDataEnvironmentContributor (Kind .BOUND_IMPORT , this .location , this .resource ,
245
251
this .fromProfileSpecificImport , this .propertySource , this .configurationPropertySource , properties ,
246
- this .configDataOptions , null );
252
+ this .configDataOptions , null , this . conversionService );
247
253
}
248
254
249
255
/**
@@ -262,7 +268,7 @@ ConfigDataEnvironmentContributor withChildren(ImportPhase importPhase,
262
268
}
263
269
return new ConfigDataEnvironmentContributor (this .kind , this .location , this .resource ,
264
270
this .fromProfileSpecificImport , this .propertySource , this .configurationPropertySource , this .properties ,
265
- this .configDataOptions , updatedChildren );
271
+ this .configDataOptions , updatedChildren , this . conversionService );
266
272
}
267
273
268
274
private void moveProfileSpecific (Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children ) {
@@ -337,7 +343,7 @@ ConfigDataEnvironmentContributor withReplacement(ConfigDataEnvironmentContributo
337
343
});
338
344
return new ConfigDataEnvironmentContributor (this .kind , this .location , this .resource ,
339
345
this .fromProfileSpecificImport , this .propertySource , this .configurationPropertySource , this .properties ,
340
- this .configDataOptions , updatedChildren );
346
+ this .configDataOptions , updatedChildren , this . conversionService );
341
347
}
342
348
343
349
@ Override
@@ -370,38 +376,45 @@ private void buildToString(String prefix, StringBuilder builder) {
370
376
/**
371
377
* Factory method to create a {@link Kind#ROOT root} contributor.
372
378
* @param contributors the immediate children of the root
379
+ * @param conversionService the conversion service to use
373
380
* @return a new {@link ConfigDataEnvironmentContributor} instance
374
381
*/
375
- static ConfigDataEnvironmentContributor of (List <ConfigDataEnvironmentContributor > contributors ) {
382
+ static ConfigDataEnvironmentContributor of (List <ConfigDataEnvironmentContributor > contributors ,
383
+ ConversionService conversionService ) {
376
384
Map <ImportPhase , List <ConfigDataEnvironmentContributor >> children = new LinkedHashMap <>();
377
385
children .put (ImportPhase .BEFORE_PROFILE_ACTIVATION , Collections .unmodifiableList (contributors ));
378
- return new ConfigDataEnvironmentContributor (Kind .ROOT , null , null , false , null , null , null , null , children );
386
+ return new ConfigDataEnvironmentContributor (Kind .ROOT , null , null , false , null , null , null , null , children ,
387
+ conversionService );
379
388
}
380
389
381
390
/**
382
391
* Factory method to create a {@link Kind#INITIAL_IMPORT initial import} contributor.
383
392
* This contributor is used to trigger initial imports of additional contributors. It
384
393
* does not contribute any properties itself.
385
394
* @param initialImport the initial import location (with placeholders resolved)
395
+ * @param conversionService the conversion service to use
386
396
* @return a new {@link ConfigDataEnvironmentContributor} instance
387
397
*/
388
- static ConfigDataEnvironmentContributor ofInitialImport (ConfigDataLocation initialImport ) {
398
+ static ConfigDataEnvironmentContributor ofInitialImport (ConfigDataLocation initialImport ,
399
+ ConversionService conversionService ) {
389
400
List <ConfigDataLocation > imports = Collections .singletonList (initialImport );
390
401
ConfigDataProperties properties = new ConfigDataProperties (imports , null );
391
402
return new ConfigDataEnvironmentContributor (Kind .INITIAL_IMPORT , null , null , false , null , null , properties ,
392
- null , null );
403
+ null , null , conversionService );
393
404
}
394
405
395
406
/**
396
407
* Factory method to create a contributor that wraps an {@link Kind#EXISTING existing}
397
408
* property source. The contributor provides access to existing properties, but
398
409
* doesn't actively import any additional contributors.
399
410
* @param propertySource the property source to wrap
411
+ * @param conversionService the conversion service to use
400
412
* @return a new {@link ConfigDataEnvironmentContributor} instance
401
413
*/
402
- static ConfigDataEnvironmentContributor ofExisting (PropertySource <?> propertySource ) {
414
+ static ConfigDataEnvironmentContributor ofExisting (PropertySource <?> propertySource ,
415
+ ConversionService conversionService ) {
403
416
return new ConfigDataEnvironmentContributor (Kind .EXISTING , null , null , false , propertySource ,
404
- ConfigurationPropertySource .from (propertySource ), null , null , null );
417
+ ConfigurationPropertySource .from (propertySource ), null , null , null , conversionService );
405
418
}
406
419
407
420
/**
@@ -413,26 +426,30 @@ static ConfigDataEnvironmentContributor ofExisting(PropertySource<?> propertySou
413
426
* @param profileSpecific if the contributor is from a profile specific import
414
427
* @param configData the config data
415
428
* @param propertySourceIndex the index of the property source that should be used
429
+ * @param conversionService the conversion service to use
416
430
* @return a new {@link ConfigDataEnvironmentContributor} instance
417
431
*/
418
432
static ConfigDataEnvironmentContributor ofUnboundImport (ConfigDataLocation location , ConfigDataResource resource ,
419
- boolean profileSpecific , ConfigData configData , int propertySourceIndex ) {
433
+ boolean profileSpecific , ConfigData configData , int propertySourceIndex ,
434
+ ConversionService conversionService ) {
420
435
PropertySource <?> propertySource = configData .getPropertySources ().get (propertySourceIndex );
421
436
ConfigData .Options options = configData .getOptions (propertySource );
422
437
ConfigurationPropertySource configurationPropertySource = ConfigurationPropertySource .from (propertySource );
423
438
return new ConfigDataEnvironmentContributor (Kind .UNBOUND_IMPORT , location , resource , profileSpecific ,
424
- propertySource , configurationPropertySource , null , options , null );
439
+ propertySource , configurationPropertySource , null , options , null , conversionService );
425
440
}
426
441
427
442
/**
428
443
* Factory method to create an {@link Kind#EMPTY_LOCATION empty location} contributor.
429
444
* @param location the location of this contributor
430
445
* @param profileSpecific if the contributor is from a profile specific import
446
+ * @param conversionService the conversion service to use
431
447
* @return a new {@link ConfigDataEnvironmentContributor} instance
432
448
*/
433
- static ConfigDataEnvironmentContributor ofEmptyLocation (ConfigDataLocation location , boolean profileSpecific ) {
449
+ static ConfigDataEnvironmentContributor ofEmptyLocation (ConfigDataLocation location , boolean profileSpecific ,
450
+ ConversionService conversionService ) {
434
451
return new ConfigDataEnvironmentContributor (Kind .EMPTY_LOCATION , location , null , profileSpecific , null , null ,
435
- null , EMPTY_LOCATION_OPTIONS , null );
452
+ null , EMPTY_LOCATION_OPTIONS , null , conversionService );
436
453
}
437
454
438
455
/**
0 commit comments