-
Notifications
You must be signed in to change notification settings - Fork 41.7k
Description
This is related to issue #5998 Im opening a new issue as per suggestion by @philwebb
I was trying out the fix from #5998 in version 1.4 and it is working for the most part. There is one small glitch though consider the below
- I have two profiles
devandprod - I have set
spring.profiles.defaulttodevusing
public static void addDefaultProfile(SpringApplication app) {
Map<String, Object> defProperties = new HashMap<>();
defProperties.put("spring.profiles.default", "dev");
app.setDefaultProperties(defProperties);
}
Note: I'm not using Collections.singletonMap as its makes the array fixed size, which causes issues as you would try to add stuff to that array in spring
3. Now if I do env.acceptsProfiles("dev") it will return false, which is OK since I didn't set it as active profile
4. now if I do --spring.profiles.active=dev I would expect env.acceptsProfiles("dev") to return true but it doesn't. seems like if the same profile is used as active and default the default one is used. Ideally it should be promoted to active
The use-case for this is if I want to do some stuff based on profiles I might be using env.acceptsProfiles("dev") to check if the profile is active and in this case its failing.
Here is a test case for the scenario, Ideally the case should pass, but with the latest spring boot release(1.4) version its failing
@Test
public void sameDefaultProfileAndActive() throws Exception {
SpringApplication application = new SpringApplication(Config.class);
application.setWebEnvironment(false);
this.context = application.run("--spring.profiles.default=customdefault",
"--spring.profiles.active=customdefault");
assertThat(this.context.getEnvironment().acceptsProfiles("customdefault"))
.isTrue();
}