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.
This commit is contained in:
Dave Syer
2014-03-03 18:08:38 +00:00
parent 8ff9e67714
commit 07b88630f4
3 changed files with 7 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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 {

View File

@@ -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