Browse Source

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
pull/2707/head
Andy Wilkinson 11 years ago
parent
commit
950eafe9cc
  1. 8
      spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java

8
spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java

@ -105,7 +105,13 @@ public class ServletListenerRegistrationBean<T extends EventListener> extends @@ -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() {

Loading…
Cancel
Save