Ensure @ActiveProfiles replaces existing profiles
Update `SpringBootContextLoader` to both add `spring.profiles.active` properties and to directly call `Environment.setActiveProfiles`. The additional `setActiveProfiles` call prevents `AbstractEnvironment` from accidentally loading `spring.profiles.active` properties directly when `doGetActiveProfiles` is called. Directly setting active profiles has only become necessary since we started adding properties using the square bracket notation. Previously we added a comma-separated list which would be picked up by both the `AbstractEnvironment` and the `ConfigurationFileApplicationListener`. Closes gh-21302
This commit is contained in:
@@ -152,6 +152,8 @@ public class SpringBootContextLoader extends AbstractContextLoader {
|
||||
}
|
||||
|
||||
private void setActiveProfiles(ConfigurableEnvironment environment, String[] profiles) {
|
||||
environment.setActiveProfiles(profiles);
|
||||
// Also add as properties to override any application.properties
|
||||
String[] pairs = new String[profiles.length];
|
||||
for (int i = 0; i < profiles.length; i++) {
|
||||
pairs[i] = "spring.profiles.active[" + i + "]=" + profiles[i];
|
||||
|
||||
Reference in New Issue
Block a user