diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index f5c2f6a0e5..dfd39bbc80 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -135,6 +135,7 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; * @author Stephane Nicoll * @author Kristine Jetzke * @author Bruce Brouwer + * @author Artsiom Yudovin */ @Configuration @ConditionalOnWebApplication(type = Type.SERVLET) @@ -153,6 +154,7 @@ public class WebMvcAutoConfiguration { @Bean @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) + @ConditionalOnProperty(prefix = "spring.mvc.hiddenmethod.filter", name = "enabled", matchIfMissing = true) public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() { return new OrderedHiddenHttpMethodFilter(); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 4ca16adb4f..2a55eec16d 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -466,6 +466,12 @@ "description": "Whether to enable Spring's HttpPutFormContentFilter.", "defaultValue": true }, + { + "name": "spring.mvc.hiddenmethod.filter.enabled", + "type": "java.lang.Boolean", + "description": "Whether to enable Spring's HiddenHttpMethodFilter.", + "defaultValue": true + }, { "name" : "spring.mvc.media-types", "type" : "java.util.Map", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 8b48bf502f..ee863d3da3 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -71,6 +71,7 @@ import org.springframework.web.accept.ParameterContentNegotiationStrategy; import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; import org.springframework.web.context.request.ServletWebRequest; +import org.springframework.web.filter.HiddenHttpMethodFilter; import org.springframework.web.filter.HttpPutFormContentFilter; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.HandlerExceptionResolver; @@ -118,6 +119,7 @@ import static org.mockito.Mockito.mock; * @author Brian Clozel * @author EddĂș MelĂ©ndez * @author Kristine Jetzke + * @author Artsiom Yudovin */ public class WebMvcAutoConfigurationTests { @@ -572,6 +574,20 @@ public class WebMvcAutoConfigurationTests { .doesNotHaveBean(HttpPutFormContentFilter.class)); } + @Test + public void hiddenHttpMethodFilterCanBeDisabled() { + this.contextRunner + .withPropertyValues("spring.mvc.hiddenmethod.filter.enabled=false") + .run((context) -> assertThat(context) + .doesNotHaveBean(HiddenHttpMethodFilter.class)); + } + + @Test + public void hiddenHttpMethodFilterEnabledByDefault() { + this.contextRunner.run((context) -> assertThat(context) + .hasSingleBean(HiddenHttpMethodFilter.class)); + } + @Test public void customConfigurableWebBindingInitializer() { this.contextRunner diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc index 6d319c696e..d2c1b547f4 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/appendix-application-properties.adoc @@ -429,6 +429,7 @@ content into your application. Rather, pick only the properties that you need. spring.mvc.dispatch-options-request=true # Whether to dispatch OPTIONS requests to the FrameworkServlet doService method. spring.mvc.favicon.enabled=true # Whether to enable resolution of favicon.ico. spring.mvc.formcontent.putfilter.enabled=true # Whether to enable Spring's HttpPutFormContentFilter. + spring.mvc.hiddenmethod.filter.enabled=true # Whether to enable Spring's HiddenHttpMethodFilter. spring.mvc.ignore-default-model-on-redirect=true # Whether the content of the "default" model should be ignored during redirect scenarios. spring.mvc.locale= # Locale to use. By default, this locale is overridden by the "Accept-Language" header. spring.mvc.locale-resolver=accept-header # Define how the locale should be resolved.