Remove default profile during environment merge

This change fixes a minor bug with the implementation of
ConfigurableEnvironment#merge, introduced in SPR-9444. During a merge
of two environments A and B, where A has default profiles [prod] and B
has default profiles [default] (the so-called 'reserved default
profile'), B would complete the merge process having a collection of
profiles reading [default, prod], which is incorrect.

This commit explicitly ensure's that B's reserved default profile is
removed if A has a set of default profiles greater than zero. If A
consists only of [default], B will inherit it during the merge
correctly; if A consists of [p1, p2], B will result in [p1, p2] as
well; if B consists of [p1] and A of [p2, p3], B will result in
[p1, p2, p3] post-merge.

Issue: SPR-9761, SPR-9444
This commit is contained in:
Chris Beams 2012-09-05 21:46:24 +02:00
parent f963d0f190
commit 9f8d219146
1 changed files with 5 additions and 2 deletions

View File

@ -409,10 +409,13 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment {
for (String profile : parent.getActiveProfiles()) {
this.activeProfiles.add(profile);
}
if (parent.getDefaultProfiles().length > 0) {
this.defaultProfiles.remove(RESERVED_DEFAULT_PROFILE_NAME);
for (String profile : parent.getDefaultProfiles()) {
this.defaultProfiles.add(profile);
}
}
}
//---------------------------------------------------------------------