From 5a9ca67fbaba2c92c5a9ef0d13f5a7a5025eedba Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 3 Jul 2023 20:37:25 +0100 Subject: [PATCH] Start building against Spring Framework 6.2.0-M2 snapshots See gh-36198 --- gradle.properties | 2 +- .../DispatcherServletAutoConfiguration.java | 8 ++++++- .../web/servlet/WebMvcProperties.java | 9 +++++++- ...spatcherServletAutoConfigurationTests.java | 23 ++++++++++++++++--- .../web/servlet/MockMvcAutoConfiguration.java | 5 ++++ .../boot/maven/JarIntegrationTests.java | 3 ++- ...tpRequestFactoriesHttpComponentsTests.java | 2 +- 7 files changed, 44 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index eb9bbe14aff..d4321ef602e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8 kotlinVersion=1.8.22 nativeBuildToolsVersion=0.9.23 -springFrameworkVersion=6.1.0-M1 +springFrameworkVersion=6.1.0-SNAPSHOT tomcatVersion=10.1.10 kotlin.stdlib.default.dependency=false diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java index 5575bde20a9..5aafbfb0091 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfiguration.java @@ -89,12 +89,18 @@ public class DispatcherServletAutoConfiguration { DispatcherServlet dispatcherServlet = new DispatcherServlet(); dispatcherServlet.setDispatchOptionsRequest(webMvcProperties.isDispatchOptionsRequest()); dispatcherServlet.setDispatchTraceRequest(webMvcProperties.isDispatchTraceRequest()); - dispatcherServlet.setThrowExceptionIfNoHandlerFound(webMvcProperties.isThrowExceptionIfNoHandlerFound()); + configureThrowExceptionIfNoHandlerFound(webMvcProperties, dispatcherServlet); dispatcherServlet.setPublishEvents(webMvcProperties.isPublishRequestHandledEvents()); dispatcherServlet.setEnableLoggingRequestDetails(webMvcProperties.isLogRequestDetails()); return dispatcherServlet; } + @SuppressWarnings({ "deprecation", "removal" }) + private void configureThrowExceptionIfNoHandlerFound(WebMvcProperties webMvcProperties, + DispatcherServlet dispatcherServlet) { + dispatcherServlet.setThrowExceptionIfNoHandlerFound(webMvcProperties.isThrowExceptionIfNoHandlerFound()); + } + @Bean @ConditionalOnBean(MultipartResolver.class) @ConditionalOnMissingBean(name = DispatcherServlet.MULTIPART_RESOLVER_BEAN_NAME) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java index 0c73524c8f9..2ca9ae03743 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcProperties.java @@ -21,6 +21,7 @@ import java.util.LinkedHashMap; import java.util.Map; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.DeprecatedConfigurationProperty; import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.validation.DefaultMessageCodesResolver; @@ -64,8 +65,10 @@ public class WebMvcProperties { /** * Whether a "NoHandlerFoundException" should be thrown if no Handler was found to * process a request. + * @deprecated since 3.2.0 for removal in 3.4.0 */ - private boolean throwExceptionIfNoHandlerFound = false; + @Deprecated(since = "3.2.0", forRemoval = true) + private boolean throwExceptionIfNoHandlerFound = true; /** * Whether logging of (potentially sensitive) request details at DEBUG and TRACE level @@ -121,10 +124,14 @@ public class WebMvcProperties { this.publishRequestHandledEvents = publishRequestHandledEvents; } + @Deprecated(since = "3.2.0", forRemoval = true) + @DeprecatedConfigurationProperty( + reason = "DispatcherServlet property is deprecated for removal and should no longer need to be configured") public boolean isThrowExceptionIfNoHandlerFound() { return this.throwExceptionIfNoHandlerFound; } + @Deprecated(since = "3.2.0", forRemoval = true) public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) { this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound; } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java index 0dbf0eaf0ad..100d36cdd91 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/DispatcherServletAutoConfigurationTests.java @@ -141,7 +141,6 @@ class DispatcherServletAutoConfigurationTests { void dispatcherServletDefaultConfig() { this.contextRunner.run((context) -> { DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class); - assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(false); assertThat(dispatcherServlet).extracting("dispatchOptionsRequest").isEqualTo(true); assertThat(dispatcherServlet).extracting("dispatchTraceRequest").isEqualTo(false); assertThat(dispatcherServlet).extracting("enableLoggingRequestDetails").isEqualTo(false); @@ -151,15 +150,24 @@ class DispatcherServletAutoConfigurationTests { }); } + @Test + @Deprecated(since = "3.2.0", forRemoval = true) + void dispatcherServletThrowExceptionIfNoHandlerFoundDefaultConfig() { + this.contextRunner.run((context) -> { + DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class); + assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(true); + }); + } + @Test void dispatcherServletCustomConfig() { this.contextRunner - .withPropertyValues("spring.mvc.throw-exception-if-no-handler-found:true", + .withPropertyValues("spring.mvc.throw-exception-if-no-handler-found:false", "spring.mvc.dispatch-options-request:false", "spring.mvc.dispatch-trace-request:true", "spring.mvc.publish-request-handled-events:false", "spring.mvc.servlet.load-on-startup=5") .run((context) -> { DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class); - assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(true); + assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(false); assertThat(dispatcherServlet).extracting("dispatchOptionsRequest").isEqualTo(false); assertThat(dispatcherServlet).extracting("dispatchTraceRequest").isEqualTo(true); assertThat(dispatcherServlet).extracting("publishEvents").isEqualTo(false); @@ -168,6 +176,15 @@ class DispatcherServletAutoConfigurationTests { }); } + @Test + @Deprecated(since = "3.2.0", forRemoval = true) + void dispatcherServletThrowExceptionIfNoHandlerFoundCustomConfig() { + this.contextRunner.withPropertyValues("spring.mvc.throw-exception-if-no-handler-found:false").run((context) -> { + DispatcherServlet dispatcherServlet = context.getBean(DispatcherServlet.class); + assertThat(dispatcherServlet).extracting("throwExceptionIfNoHandlerFound").isEqualTo(false); + }); + } + @Configuration(proxyBeanMethods = false) static class MultipartConfiguration { diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java index 6d429eb4fae..9e944e4fad3 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/main/java/org/springframework/boot/test/autoconfigure/web/servlet/MockMvcAutoConfiguration.java @@ -131,6 +131,11 @@ public class MockMvcAutoConfiguration { public void customize(DispatcherServlet dispatcherServlet) { dispatcherServlet.setDispatchOptionsRequest(this.webMvcProperties.isDispatchOptionsRequest()); dispatcherServlet.setDispatchTraceRequest(this.webMvcProperties.isDispatchTraceRequest()); + configureThrowExceptionIfNoHandlerFound(dispatcherServlet); + } + + @SuppressWarnings({ "deprecation", "removal" }) + private void configureThrowExceptionIfNoHandlerFound(DispatcherServlet dispatcherServlet) { dispatcherServlet .setThrowExceptionIfNoHandlerFound(this.webMvcProperties.isThrowExceptionIfNoHandlerFound()); } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java index 46ad4f7f3a8..07eeaaa70bc 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/JarIntegrationTests.java @@ -428,7 +428,8 @@ class JarIntegrationTests extends AbstractArchiveIntegrationTests { void whenJarIsRepackagedWithOutputTimestampConfiguredThenLibrariesAreSorted(MavenBuild mavenBuild) { mavenBuild.project("jar-output-timestamp").execute((project) -> { File repackaged = new File(project, "target/jar-output-timestamp-0.0.1.BUILD-SNAPSHOT.jar"); - List sortedLibs = Arrays.asList("BOOT-INF/lib/jakarta.servlet-api", "BOOT-INF/lib/spring-aop", + List sortedLibs = Arrays.asList("BOOT-INF/lib/jakarta.servlet-api", + "BOOT-INF/lib/micrometer-commons", "BOOT-INF/lib/micrometer-observation", "BOOT-INF/lib/spring-aop", "BOOT-INF/lib/spring-beans", "BOOT-INF/lib/spring-boot-jarmode-layertools", "BOOT-INF/lib/spring-context", "BOOT-INF/lib/spring-core", "BOOT-INF/lib/spring-expression", "BOOT-INF/lib/spring-jcl"); diff --git a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesHttpComponentsTests.java b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesHttpComponentsTests.java index 98b9095afec..b8df330e779 100644 --- a/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesHttpComponentsTests.java +++ b/spring-boot-project/spring-boot/src/test/java/org/springframework/boot/web/client/ClientHttpRequestFactoriesHttpComponentsTests.java @@ -39,7 +39,7 @@ class ClientHttpRequestFactoriesHttpComponentsTests @Override protected long connectTimeout(HttpComponentsClientHttpRequestFactory requestFactory) { - return (int) ReflectionTestUtils.getField(requestFactory, "connectTimeout"); + return (long) ReflectionTestUtils.getField(requestFactory, "connectTimeout"); } @Override