Skip to content

Commit c11b28c

Browse files
committed
Align default for OPTIONS request dispatching with Spring Framework 4.3
Closes gh-5965
1 parent dcb4fe8 commit c11b28c

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class WebMvcProperties {
5959
/**
6060
* Dispatch OPTIONS requests to the FrameworkServlet doService method.
6161
*/
62-
private boolean dispatchOptionsRequest = false;
62+
private boolean dispatchOptionsRequest = true;
6363

6464
/**
6565
* If the content of the "default" model should be ignored during redirect scenarios.

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/DispatcherServletAutoConfigurationTests.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* Tests for {@link DispatcherServletAutoConfiguration}.
4444
*
4545
* @author Dave Syer
46+
* @author Andy Wilkinson
4647
*/
4748
public class DispatcherServletAutoConfigurationTests {
4849

@@ -146,21 +147,38 @@ public void renamesMultipartResolver() throws Exception {
146147
}
147148

148149
@Test
149-
public void dispatcherServletConfig() {
150+
public void dispatcherServletDefaultConfig() {
151+
this.context = new AnnotationConfigWebApplicationContext();
152+
this.context.setServletContext(new MockServletContext());
153+
this.context.register(ServerPropertiesAutoConfiguration.class,
154+
DispatcherServletAutoConfiguration.class);
155+
this.context.refresh();
156+
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
157+
assertThat(bean).extracting("throwExceptionIfNoHandlerFound")
158+
.containsExactly(false);
159+
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true);
160+
assertThat(bean).extracting("dispatchTraceRequest").containsExactly(false);
161+
assertThat(new DirectFieldAccessor(
162+
this.context.getBean("dispatcherServletRegistration"))
163+
.getPropertyValue("loadOnStartup")).isEqualTo(-1);
164+
}
165+
166+
@Test
167+
public void dispatcherServletCustomConfig() {
150168
this.context = new AnnotationConfigWebApplicationContext();
151169
this.context.setServletContext(new MockServletContext());
152170
this.context.register(ServerPropertiesAutoConfiguration.class,
153171
DispatcherServletAutoConfiguration.class);
154172
EnvironmentTestUtils.addEnvironment(this.context,
155173
"spring.mvc.throw-exception-if-no-handler-found:true",
156-
"spring.mvc.dispatch-options-request:true",
174+
"spring.mvc.dispatch-options-request:false",
157175
"spring.mvc.dispatch-trace-request:true",
158176
"spring.mvc.servlet.load-on-startup=5");
159177
this.context.refresh();
160178
DispatcherServlet bean = this.context.getBean(DispatcherServlet.class);
161179
assertThat(bean).extracting("throwExceptionIfNoHandlerFound")
162180
.containsExactly(true);
163-
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(true);
181+
assertThat(bean).extracting("dispatchOptionsRequest").containsExactly(false);
164182
assertThat(bean).extracting("dispatchTraceRequest").containsExactly(true);
165183
assertThat(new DirectFieldAccessor(
166184
this.context.getBean("dispatcherServletRegistration"))

0 commit comments

Comments
 (0)