Improve diagnostics when ServletContext.addListener fails

The various servlet containers that we support vary in the quality
of their diagnostics when ServletContext.addListener fails. To make
problem diagnosis easier, this commit ensures that the toString of the
the listener that was being added is included in the exception that's
thrown when a failure occurs.

Closes gh-2197
This commit is contained in:
Andy Wilkinson 2014-12-18 15:18:40 +00:00
parent 5c67e6f141
commit 950eafe9cc
1 changed files with 7 additions and 1 deletions

View File

@ -105,7 +105,13 @@ public class ServletListenerRegistrationBean<T extends EventListener> extends
logger.info("Listener " + this.listener + " was not registered (disabled)");
return;
}
servletContext.addListener(this.listener);
try {
servletContext.addListener(this.listener);
}
catch (RuntimeException ex) {
throw new IllegalStateException("Failed to add listener '" + this.listener
+ "' to servlet context", ex);
}
}
public T getListener() {