From 07b88630f4af7de33be27d3ee0c9bef257233db5 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Mon, 3 Mar 2014 18:08:38 +0000 Subject: [PATCH] Be defensive with auto-config of Servlet 3.0 features There's no explicit support for older Servlet specs in Spring Boot, but we can at least make it easy for others to provide such support by not adding stuff to the context when in an older container. --- .../actuate/autoconfigure/MetricFilterAutoConfiguration.java | 3 ++- .../actuate/autoconfigure/TraceWebFilterAutoConfiguration.java | 3 ++- .../autoconfigure/web/DispatcherServletAutoConfiguration.java | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java index d7f1528cd4..aa6b981819 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -22,6 +22,7 @@ import javax.servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.Servlet; import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -49,7 +50,7 @@ import org.springframework.web.util.UrlPathHelper; */ @Configuration @ConditionalOnBean({ CounterService.class, GaugeService.class }) -@ConditionalOnClass({ Servlet.class }) +@ConditionalOnClass({ Servlet.class, ServletRegistration.class }) @AutoConfigureAfter(MetricRepositoryAutoConfiguration.class) public class MetricFilterAutoConfiguration { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java index fa812f3b6a..d174162fca 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/TraceWebFilterAutoConfiguration.java @@ -17,6 +17,7 @@ package org.springframework.boot.actuate.autoconfigure; import javax.servlet.Servlet; +import javax.servlet.ServletRegistration; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +37,7 @@ import org.springframework.web.servlet.DispatcherServlet; * * @author Dave Syer */ -@ConditionalOnClass({ Servlet.class, DispatcherServlet.class }) +@ConditionalOnClass({ Servlet.class, DispatcherServlet.class, ServletRegistration.class }) @AutoConfigureAfter(TraceRepositoryAutoConfiguration.class) public class TraceWebFilterAutoConfiguration { diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java index d0b5d5d9ce..da8602716a 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfiguration.java @@ -19,6 +19,8 @@ package org.springframework.boot.autoconfigure.web; import java.util.Arrays; import java.util.List; +import javax.servlet.ServletRegistration; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -61,6 +63,7 @@ public class DispatcherServletAutoConfiguration { @Configuration @Conditional(DefaultDispatcherServletCondition.class) + @ConditionalOnClass(ServletRegistration.class) protected static class DispatcherServletConfiguration { @Autowired