null if none
*/
String getId();
/**
* Return a friendly name for this context.
- * @return a display name for this context
+ * @return a display name for this context (never null)
*/
String getDisplayName();
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
index a905a93d490..d1deba73686 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractApplicationContext.java
@@ -144,6 +144,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
/** Unique id for this context, if any */
private String id = ObjectUtils.identityToString(this);
+ /** Display name */
+ private String displayName = ObjectUtils.identityToString(this);
+
/** Parent context */
private ApplicationContext parent;
@@ -151,9 +154,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
private final Listnull if none
+ */
public String getId() {
return this.id;
}
+ /**
+ * Set a friendly name for this context.
+ * Typically done during initialization of concrete context implementations.
+ * Default is the object id of the context instance.
+ */
+ public void setDisplayName(String displayName) {
+ Assert.hasLength(displayName, "Display name must not be empty");
+ this.displayName = displayName;
+ }
+
+ /**
+ * Return a friendly name for this context.
+ * @return a display name for this context (never null)
+ */
+ public String getDisplayName() {
+ return this.displayName;
+ }
+
/**
* Return the parent context, or null if there is no parent
* (that is, this context is the root of the context hierarchy).
@@ -234,21 +256,6 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
return getBeanFactory();
}
- /**
- * Set a friendly name for this context.
- * Typically done during initialization of concrete context implementations.
- */
- public void setDisplayName(String displayName) {
- this.displayName = displayName;
- }
-
- /**
- * Return a friendly name for this context.
- */
- public String getDisplayName() {
- return (this.displayName != null ? this.displayName : getId());
- }
-
/**
* Return the timestamp (ms) when this context was first loaded.
*/
@@ -267,7 +274,7 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
public void publishEvent(ApplicationEvent event) {
Assert.notNull(event, "Event must not be null");
if (logger.isTraceEnabled()) {
- logger.trace("Publishing event in context [" + getId() + "]: " + event);
+ logger.trace("Publishing event in " + getDisplayName() + ": " + event);
}
getApplicationEventMulticaster().multicastEvent(event);
if (this.parent != null) {
@@ -417,15 +424,9 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
protected ConfigurableListableBeanFactory obtainFreshBeanFactory() {
refreshBeanFactory();
ConfigurableListableBeanFactory beanFactory = getBeanFactory();
-
- if (logger.isInfoEnabled()) {
- logger.info("Bean factory for application context [" + getId() + "]: " +
- ObjectUtils.identityToString(beanFactory));
- }
if (logger.isDebugEnabled()) {
- logger.debug(beanFactory.getBeanDefinitionCount() + " beans defined in " + this);
+ logger.debug("Bean factory for " + getDisplayName() + ": " + beanFactory);
}
-
return beanFactory;
}
@@ -1161,16 +1162,15 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
*/
@Override
public String toString() {
- StringBuilder sb = new StringBuilder(getId());
- sb.append(": display name [").append(getDisplayName());
- sb.append("]; startup date [").append(new Date(getStartupDate()));
+ StringBuilder sb = new StringBuilder(getDisplayName());
+ sb.append(": startup date [").append(new Date(getStartupDate()));
sb.append("]; ");
ApplicationContext parent = getParent();
if (parent == null) {
sb.append("root of context hierarchy");
}
else {
- sb.append("parent: ").append(parent.getId());
+ sb.append("parent: ").append(parent.getDisplayName());
}
return sb.toString();
}
diff --git a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
index 161ecdce94e..839fd59b7ef 100644
--- a/org.springframework.context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
+++ b/org.springframework.context/src/main/java/org/springframework/context/support/AbstractRefreshableApplicationContext.java
@@ -130,8 +130,7 @@ public abstract class AbstractRefreshableApplicationContext extends AbstractAppl
}
}
catch (IOException ex) {
- throw new ApplicationContextException(
- "I/O error parsing XML document for application context [" + getDisplayName() + "]", ex);
+ throw new ApplicationContextException("I/O error parsing XML document for " + getDisplayName(), ex);
}
}