From 950eafe9ccd47c3d505241c6e1a1036ece027453 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 18 Dec 2014 15:18:40 +0000 Subject: [PATCH] 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 --- .../context/embedded/ServletListenerRegistrationBean.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java index db3de95faea..b0f31731e39 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/embedded/ServletListenerRegistrationBean.java @@ -105,7 +105,13 @@ public class ServletListenerRegistrationBean 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() {