3434import org .springframework .boot .context .properties .EnableConfigurationProperties ;
3535import org .springframework .boot .context .properties .bind .Bindable ;
3636import org .springframework .boot .context .properties .bind .Binder ;
37+ import org .springframework .boot .context .properties .bind .PropertySourcesPlaceholdersResolver ;
38+ import org .springframework .boot .context .properties .source .ConfigurationPropertySource ;
3739import org .springframework .boot .logging .LogFile ;
3840import org .springframework .boot .logging .LoggingInitializationContext ;
3941import org .springframework .boot .logging .LoggingSystem ;
4648import org .springframework .context .annotation .Configuration ;
4749import org .springframework .context .event .ContextRefreshedEvent ;
4850import org .springframework .core .Ordered ;
51+ import org .springframework .core .ResolvableType ;
4952import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
5053import org .springframework .core .env .AbstractEnvironment ;
5154import org .springframework .core .env .CompositePropertySource ;
5457import org .springframework .core .env .Environment ;
5558import org .springframework .core .env .MutablePropertySources ;
5659import org .springframework .core .env .PropertySource ;
57- import org .springframework .util .StringUtils ;
5860
5961import static org .springframework .cloud .bootstrap .encrypt .AbstractEnvironmentDecrypt .DECRYPTED_PROPERTY_SOURCE_NAME ;
6062import static org .springframework .core .env .StandardEnvironment .SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME ;
6163
6264/**
6365 * @author Dave Syer
66+ * @author Yanming Zhou
6467 *
6568 */
6669@ Configuration (proxyBeanMethods = false )
@@ -294,6 +297,7 @@ private List<String> addActiveProfilesTo(List<String> profiles, PropertySource<?
294297 return addProfilesTo (profiles , propertySource , AbstractEnvironment .ACTIVE_PROFILES_PROPERTY_NAME , environment );
295298 }
296299
300+ @ SuppressWarnings ("unchecked" )
297301 private <T extends Collection <String >> T addProfilesTo (T profiles , PropertySource <?> propertySource ,
298302 String property , ConfigurableEnvironment environment ) {
299303 if (propertySource instanceof CompositePropertySource ) {
@@ -303,27 +307,19 @@ private <T extends Collection<String>> T addProfilesTo(T profiles, PropertySourc
303307 }
304308 }
305309 else {
306- Collections .addAll (profiles , getProfilesForValue (propertySource .getProperty (property ), environment ));
310+ // bootstrapProperties is loaded as package-private
311+ // ConfigurationPropertySourcesPropertySource
312+ ResolvableType requiredType = ResolvableType .forClassWithGenerics (PropertySource .class ,
313+ ResolvableType .forClassWithGenerics (Iterable .class , ConfigurationPropertySource .class ));
314+ if (requiredType .isInstance (propertySource )) {
315+ Binder binder = new Binder ((Iterable <ConfigurationPropertySource >) propertySource .getSource (),
316+ new PropertySourcesPlaceholdersResolver (environment ));
317+ binder .bind (property , Bindable .listOf (String .class )).ifBound (profiles ::addAll );
318+ }
307319 }
308320 return profiles ;
309321 }
310322
311- private String [] getProfilesForValue (Object property , ConfigurableEnvironment environment ) {
312- final String value = (property == null ? null : property .toString ());
313- return property == null ? new String [0 ] : resolvePlaceholdersInProfiles (value , environment );
314- }
315-
316- private String [] resolvePlaceholdersInProfiles (String profiles , ConfigurableEnvironment environment ) {
317- return Arrays .stream (StringUtils .tokenizeToStringArray (profiles , "," )).map (s -> {
318- if (s .startsWith ("${" ) && s .endsWith ("}" )) {
319- return environment .resolvePlaceholders (s );
320- }
321- else {
322- return s ;
323- }
324- }).toArray (String []::new );
325- }
326-
327323 /*
328324 * The ConextRefreshedEvent gets called at the end of the boostrap phase after config
329325 * data is loaded during bootstrap. This will run and do an "initial fetch" of
0 commit comments