Commit 9f241a9e authored by Dave Syer's avatar Dave Syer

Ensure app index is used when profiles actrive

parent fe1336ed
...@@ -91,15 +91,15 @@ public class ContextIdApplicationContextInitializer implements ...@@ -91,15 +91,15 @@ public class ContextIdApplicationContextInitializer implements
private String getApplicationId(ConfigurableEnvironment environment) { private String getApplicationId(ConfigurableEnvironment environment) {
String name = environment.resolvePlaceholders(this.name); String name = environment.resolvePlaceholders(this.name);
String index = environment.resolvePlaceholders(INDEX_PATTERN); String index = environment.resolvePlaceholders(INDEX_PATTERN);
if (!"null".equals(index)) {
return name + ":" + index;
}
String profiles = StringUtils.arrayToCommaDelimitedString(environment String profiles = StringUtils.arrayToCommaDelimitedString(environment
.getActiveProfiles()); .getActiveProfiles());
if (StringUtils.hasText(profiles)) { if (StringUtils.hasText(profiles)) {
name = name + ":" + profiles; name = name + ":" + profiles;
} }
if (!"null".equals(index)) {
name = name + ":" + index;
}
return name; return name;
} }
......
...@@ -51,9 +51,9 @@ public class ContextIdApplicationContextInitializerTests { ...@@ -51,9 +51,9 @@ public class ContextIdApplicationContextInitializerTests {
public void testNameAndProfiles() { public void testNameAndProfiles() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(); ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
TestUtils.addEnviroment(context, "spring.application.name:foo", TestUtils.addEnviroment(context, "spring.application.name:foo",
"spring.profiles.active: spam,bar"); "spring.profiles.active: spam,bar", "spring.application.index:12");
this.initializer.initialize(context); this.initializer.initialize(context);
assertEquals("foo:spam,bar", context.getId()); assertEquals("foo:spam,bar:12", context.getId());
} }
@Test @Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment