diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index ae65b8183d..38992b5030 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -107,13 +107,13 @@ public class WebMvcAutoConfiguration { @Bean @ConditionalOnMissingBean(HiddenHttpMethodFilter.class) - public HiddenHttpMethodFilter hiddenHttpMethodFilter() { + public OrderedHiddenHttpMethodFilter hiddenHttpMethodFilter() { return new OrderedHiddenHttpMethodFilter(); } @Bean @ConditionalOnMissingBean(HttpPutFormContentFilter.class) - public HttpPutFormContentFilter httpPutFormContentFilter() { + public OrderedHttpPutFormContentFilter httpPutFormContentFilter() { return new OrderedHttpPutFormContentFilter(); } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index d178194521..099838664e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -41,6 +41,7 @@ import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebAppl import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizerBeanPostProcessor; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.MockEmbeddedServletContainerFactory; +import org.springframework.boot.context.web.OrderedHttpPutFormContentFilter; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -51,6 +52,7 @@ import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.util.ReflectionUtils; import org.springframework.util.StringUtils; +import org.springframework.web.filter.HttpPutFormContentFilter; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.HandlerMapping; import org.springframework.web.servlet.LocaleResolver; @@ -441,6 +443,22 @@ public class WebMvcAutoConfigurationTests { assertEquals(123456L, actual); } + @Test + public void httpPutFormContentFilterIsAutoConfigured() { + load(); + assertThat(this.context.getBeansOfType(OrderedHttpPutFormContentFilter.class) + .size(), is(equalTo(1))); + } + + @Test + public void httpPutFormContentFilterCanBeOverridden() { + load(CustomHttpPutFormContentFilter.class); + assertThat(this.context.getBeansOfType(OrderedHttpPutFormContentFilter.class) + .size(), is(equalTo(0))); + assertThat(this.context.getBeansOfType(HttpPutFormContentFilter.class).size(), + is(equalTo(1))); + } + @SuppressWarnings("unchecked") private void load(Class config, String... environment) { this.context = new AnnotationConfigEmbeddedWebApplicationContext(); @@ -552,4 +570,14 @@ public class WebMvcAutoConfigurationTests { } + @Configuration + static class CustomHttpPutFormContentFilter { + + @Bean + public HttpPutFormContentFilter customHttpPutFormContentFilter() { + return new HttpPutFormContentFilter(); + } + + } + } diff --git a/spring-boot/src/main/java/org/springframework/boot/context/web/OrderedHttpPutFormContentFilter.java b/spring-boot/src/main/java/org/springframework/boot/context/web/OrderedHttpPutFormContentFilter.java index b42a7d9729..bce6aeb5e9 100644 --- a/spring-boot/src/main/java/org/springframework/boot/context/web/OrderedHttpPutFormContentFilter.java +++ b/spring-boot/src/main/java/org/springframework/boot/context/web/OrderedHttpPutFormContentFilter.java @@ -25,7 +25,8 @@ import org.springframework.web.filter.HttpPutFormContentFilter; * @author Joao Pedro Evangelista * @since 1.3.0 */ -public class OrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements Ordered { +public class OrderedHttpPutFormContentFilter extends HttpPutFormContentFilter implements + Ordered { /** * Higher order to ensure the filter is applied before Spring Security.