From c11b28c3c72d3838092ad67df2d7c9abe59e4f3b Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 13 May 2016 16:18:54 +0100 Subject: [PATCH] Align default for OPTIONS request dispatching with Spring Framework 4.3 Closes gh-5965 --- .../autoconfigure/web/WebMvcProperties.java | 2 +- ...spatcherServletAutoConfigurationTests.java | 24 ++++++++++++++++--- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java index 0ea3895548..85c8b78fca 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java @@ -59,7 +59,7 @@ public class WebMvcProperties { /** * Dispatch OPTIONS requests to the FrameworkServlet doService method. */ - private boolean dispatchOptionsRequest = false; + private boolean dispatchOptionsRequest = true; /** * If the content of the "default" model should be ignored during redirect scenarios. diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfigurationTests.java index 73f52c62c0..e9c7472612 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfigurationTests.java @@ -43,6 +43,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link DispatcherServletAutoConfiguration}. * * @author Dave Syer + * @author Andy Wilkinson */ public class DispatcherServletAutoConfigurationTests { @@ -146,21 +147,38 @@ public class DispatcherServletAutoConfigurationTests { } @Test - public void dispatcherServletConfig() { + public void dispatcherServletDefaultConfig() { + this.context = new AnnotationConfigWebApplicationContext(); + this.context.setServletContext(new MockServletContext()); + this.context.register(ServerPropertiesAutoConfiguration.class, + DispatcherServletAutoConfiguration.class); + this.context.refresh(); + DispatcherServlet bean = this.context.getBean(DispatcherServlet.class); + assertThat(bean).extracting("throwExceptionIfNoHandlerFound") + .containsExactly(false); + assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true); + assertThat(bean).extracting("dispatchTraceRequest").containsExactly(false); + assertThat(new DirectFieldAccessor( + this.context.getBean("dispatcherServletRegistration")) + .getPropertyValue("loadOnStartup")).isEqualTo(-1); + } + + @Test + public void dispatcherServletCustomConfig() { this.context = new AnnotationConfigWebApplicationContext(); this.context.setServletContext(new MockServletContext()); this.context.register(ServerPropertiesAutoConfiguration.class, DispatcherServletAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "spring.mvc.throw-exception-if-no-handler-found:true", - "spring.mvc.dispatch-options-request:true", + "spring.mvc.dispatch-options-request:false", "spring.mvc.dispatch-trace-request:true", "spring.mvc.servlet.load-on-startup=5"); this.context.refresh(); DispatcherServlet bean = this.context.getBean(DispatcherServlet.class); assertThat(bean).extracting("throwExceptionIfNoHandlerFound") .containsExactly(true); - assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true); + assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(false); assertThat(bean).extracting("dispatchTraceRequest").containsExactly(true); assertThat(new DirectFieldAccessor( this.context.getBean("dispatcherServletRegistration"))