Ensure app index is used when profiles actrive

This commit is contained in:
Dave Syer
2013-12-26 14:32:58 +00:00
parent fe1336edcc
commit 9f241a9e82
2 changed files with 5 additions and 5 deletions

View File

@@ -91,15 +91,15 @@ public class ContextIdApplicationContextInitializer implements
private String getApplicationId(ConfigurableEnvironment environment) {
String name = environment.resolvePlaceholders(this.name);
String index = environment.resolvePlaceholders(INDEX_PATTERN);
if (!"null".equals(index)) {
return name + ":" + index;
}
String profiles = StringUtils.arrayToCommaDelimitedString(environment
.getActiveProfiles());
if (StringUtils.hasText(profiles)) {
name = name + ":" + profiles;
}
if (!"null".equals(index)) {
name = name + ":" + index;
}
return name;
}

View File

@@ -51,9 +51,9 @@ public class ContextIdApplicationContextInitializerTests {
public void testNameAndProfiles() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
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);
assertEquals("foo:spam,bar", context.getId());
assertEquals("foo:spam,bar:12", context.getId());
}
@Test