File tree Expand file tree Collapse file tree 2 files changed +21
-11
lines changed
main/java/org/springframework/boot/context/config
test/java/org/springframework/boot/context/config Expand file tree Collapse file tree 2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change @@ -314,17 +314,15 @@ public void load() throws IOException {
314
314
maybeActivateProfiles (
315
315
this .environment .getProperty (ACTIVE_PROFILES_PROPERTY ));
316
316
}
317
- else {
318
- // Pre-existing active profiles set via Environment.setActiveProfiles()
319
- // are additional profiles and config files are allowed to add more if
320
- // they want to, so don't call addActiveProfiles() here.
321
- List <String > list = new ArrayList <String >(
322
- Arrays .asList (this .environment .getActiveProfiles ()));
323
- // Reverse them so the order is the same as from getProfilesForValue()
324
- // (last one wins when properties are eventually resolved)
325
- Collections .reverse (list );
326
- this .profiles .addAll (list );
327
- }
317
+ // Pre-existing active profiles set via Environment.setActiveProfiles()
318
+ // are additional profiles and config files are allowed to add more if
319
+ // they want to, so don't call addActiveProfiles() here.
320
+ List <String > list = new ArrayList <String >(
321
+ Arrays .asList (this .environment .getActiveProfiles ()));
322
+ // Reverse them so the order is the same as from getProfilesForValue()
323
+ // (last one wins when properties are eventually resolved)
324
+ Collections .reverse (list );
325
+ this .profiles .addAll (list );
328
326
329
327
// The default profile for these purposes is represented as null. We add it
330
328
// last so that it is first out of the queue (active profiles will then
Original file line number Diff line number Diff line change @@ -341,6 +341,18 @@ public void profilePropertiesUsedInPlaceholders() throws Exception {
341
341
assertThat (property , equalTo ("fromprofilepropertiesfile" ));
342
342
}
343
343
344
+ @ Test
345
+ public void profilesAddedToEnvironmentAndViaProperty () throws Exception {
346
+ EnvironmentTestUtils .addEnvironment (this .environment ,
347
+ "spring.profiles.active:foo" );
348
+ this .environment .addActiveProfile ("dev" );
349
+ this .initializer .onApplicationEvent (this .event );
350
+ assertThat (this .environment .getActiveProfiles (),
351
+ equalTo (new String [] { "foo" , "dev" }));
352
+ assertThat (this .environment .getProperty ("my.property" ),
353
+ equalTo ("fromdevpropertiesfile" ));
354
+ }
355
+
344
356
@ Test
345
357
public void yamlProfiles () throws Exception {
346
358
this .initializer .setSearchNames ("testprofiles" );
You can’t perform that action at this time.
0 commit comments