From 971bdd36fe6c3587e96b9d57f454c2d3cf10bc82 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Oct 2021 17:50:59 +0100 Subject: [PATCH 1/2] Start building against Framework 5.3.12 snapshots This reverts commit b32a38a8147ccc84cfdfe9edba3eface01fa1a04. See gh-28223 Closes gh-28369 --- .../reactive/WebFluxAutoConfiguration.java | 35 +++++-------------- .../web/servlet/WebMvcAutoConfiguration.java | 13 ++----- .../WebFluxAutoConfigurationTests.java | 9 +++-- .../META-INF/resources/webjars/webjar | 0 .../spring-boot-dependencies/build.gradle | 2 +- 5 files changed, 17 insertions(+), 42 deletions(-) delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java index 7f9aa1a5e4..870adeaeff 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java @@ -17,8 +17,6 @@ package org.springframework.boot.autoconfigure.web.reactive; import java.time.Duration; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -51,7 +49,6 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; -import org.springframework.core.io.ResourceLoader; import org.springframework.format.FormatterRegistry; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.codec.ServerCodecConfigurer; @@ -154,14 +151,12 @@ public class WebFluxAutoConfiguration { private final ObjectProvider viewResolvers; - private final ResourceLoader resourceLoader; - public WebFluxConfig(org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties, WebProperties webProperties, WebFluxProperties webFluxProperties, ListableBeanFactory beanFactory, ObjectProvider resolvers, ObjectProvider codecCustomizers, ObjectProvider resourceHandlerRegistrationCustomizer, - ObjectProvider viewResolvers, ResourceLoader resourceLoader) { + ObjectProvider viewResolvers) { this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(); this.webFluxProperties = webFluxProperties; @@ -170,7 +165,6 @@ public class WebFluxAutoConfiguration { this.codecCustomizers = codecCustomizers; this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizer.getIfAvailable(); this.viewResolvers = viewResolvers; - this.resourceLoader = resourceLoader; } @Override @@ -190,28 +184,17 @@ public class WebFluxAutoConfiguration { return; } if (!registry.hasMappingForPattern("/webjars/**")) { - String webjarsLocation = "classpath:/META-INF/resources/webjars/"; - if (this.resourceLoader.getResource(webjarsLocation).exists()) { - ResourceHandlerRegistration registration = registry.addResourceHandler("/webjars/**") - .addResourceLocations(webjarsLocation); - configureResourceCaching(registration); - customizeResourceHandlerRegistration(registration); - } + ResourceHandlerRegistration registration = registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + configureResourceCaching(registration); + customizeResourceHandlerRegistration(registration); } String staticPathPattern = this.webFluxProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { - List foundLocations = new ArrayList<>(); - for (String staticLocation : this.resourceProperties.getStaticLocations()) { - if (this.resourceLoader.getResource(staticLocation).exists()) { - foundLocations.add(staticLocation); - } - } - if (!foundLocations.isEmpty()) { - ResourceHandlerRegistration registration = registry.addResourceHandler(staticPathPattern) - .addResourceLocations(foundLocations.toArray(new String[0])); - configureResourceCaching(registration); - customizeResourceHandlerRegistration(registration); - } + ResourceHandlerRegistration registration = registry.addResourceHandler(staticPathPattern) + .addResourceLocations(this.resourceProperties.getStaticLocations()); + configureResourceCaching(registration); + customizeResourceHandlerRegistration(registration); } } 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 6c7ea8dc3c..2e8de24cac 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 @@ -201,8 +201,6 @@ public class WebMvcAutoConfiguration { private final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer; - private final ResourceLoader resourceLoader; - private ServletContext servletContext; public WebMvcAutoConfigurationAdapter( @@ -211,7 +209,7 @@ public class WebMvcAutoConfiguration { ObjectProvider messageConvertersProvider, ObjectProvider resourceHandlerRegistrationCustomizerProvider, ObjectProvider dispatcherServletPath, - ObjectProvider> servletRegistrations, ResourceLoader resourceLoader) { + ObjectProvider> servletRegistrations) { this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(); this.mvcProperties = mvcProperties; @@ -220,7 +218,6 @@ public class WebMvcAutoConfiguration { this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider.getIfAvailable(); this.dispatcherServletPath = dispatcherServletPath; this.servletRegistrations = servletRegistrations; - this.resourceLoader = resourceLoader; this.mvcProperties.checkConfiguration(); } @@ -337,11 +334,7 @@ public class WebMvcAutoConfiguration { logger.debug("Default resource handling disabled"); return; } - Resource webjarsLocationResource = this.resourceLoader - .getResource("classpath:/META-INF/resources/webjars/"); - if (webjarsLocationResource.exists()) { - addResourceHandler(registry, "/webjars/**", webjarsLocationResource); - } + addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/"); addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> { registration.addResourceLocations(this.resourceProperties.getStaticLocations()); if (this.servletContext != null) { @@ -351,7 +344,7 @@ public class WebMvcAutoConfiguration { }); } - private void addResourceHandler(ResourceHandlerRegistry registry, String pattern, Resource... locations) { + private void addResourceHandler(ResourceHandlerRegistry registry, String pattern, String... locations) { addResourceHandler(registry, pattern, (registration) -> registration.addResourceLocations(locations)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index 36381b03b9..20a5b410f4 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -150,10 +150,9 @@ class WebFluxAutoConfigurationTests { SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class); assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**"); - assertThat(staticHandler).extracting("locationValues").asList().hasSize(2); - assertThat(staticHandler.getLocations()).hasSize(2); - assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [META-INF/resources/]"); - assertThat(staticHandler.getLocations().get(1)).hasToString("class path resource [public/]"); + assertThat(staticHandler).extracting("locationValues").asList().hasSize(4); + assertThat(staticHandler.getLocations()).hasSize(1); + assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [public/]"); assertThat(hm.getUrlMap().get("/webjars/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler webjarsHandler = (ResourceWebHandler) hm.getUrlMap().get("/webjars/**"); assertThat(webjarsHandler).extracting("locationValues").asList() @@ -167,7 +166,7 @@ class WebFluxAutoConfigurationTests { SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class); assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**"); - assertThat(staticHandler).extracting("locationValues").asList().hasSize(2); + assertThat(staticHandler).extracting("locationValues").asList().hasSize(4); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 6a18784a74..a5cafffcf2 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1578,7 +1578,7 @@ bom { ] } } - library("Spring Framework", "5.3.11") { + library("Spring Framework", "5.3.12-SNAPSHOT") { group("org.springframework") { imports = [ "spring-framework-bom" From f2ef8f92453299cfe071ea687c7d3b0efe7dd82f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 19 Oct 2021 18:41:23 +0100 Subject: [PATCH 2/2] Start building against Spring Framework 5.3.12 snapshots This reverts commit 196013fc3929106e183241e6af9b9b534c9cdc2b, reversing changes made to 8b0c563832844938e3f5ad3ae2da1a240ff80d67. Closes gh-28384 See gh-28241 --- .../reactive/WebFluxAutoConfiguration.java | 35 +++++-------------- .../web/servlet/WebMvcAutoConfiguration.java | 13 ++----- .../WebFluxAutoConfigurationTests.java | 9 +++-- .../META-INF/resources/webjars/webjar | 0 .../spring-boot-dependencies/build.gradle | 2 +- 5 files changed, 17 insertions(+), 42 deletions(-) delete mode 100644 spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java index e3f227af77..b1e6969ee7 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfiguration.java @@ -17,8 +17,6 @@ package org.springframework.boot.autoconfigure.web.reactive; import java.time.Duration; -import java.util.ArrayList; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -52,7 +50,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; -import org.springframework.core.io.ResourceLoader; import org.springframework.format.FormatterRegistry; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.codec.ServerCodecConfigurer; @@ -159,14 +156,12 @@ public class WebFluxAutoConfiguration { private final ObjectProvider viewResolvers; - private final ResourceLoader resourceLoader; - public WebFluxConfig(org.springframework.boot.autoconfigure.web.ResourceProperties resourceProperties, WebProperties webProperties, WebFluxProperties webFluxProperties, ListableBeanFactory beanFactory, ObjectProvider resolvers, ObjectProvider codecCustomizers, ObjectProvider resourceHandlerRegistrationCustomizer, - ObjectProvider viewResolvers, ResourceLoader resourceLoader) { + ObjectProvider viewResolvers) { this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(); this.webFluxProperties = webFluxProperties; @@ -175,7 +170,6 @@ public class WebFluxAutoConfiguration { this.codecCustomizers = codecCustomizers; this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizer.getIfAvailable(); this.viewResolvers = viewResolvers; - this.resourceLoader = resourceLoader; } @Override @@ -195,28 +189,17 @@ public class WebFluxAutoConfiguration { return; } if (!registry.hasMappingForPattern("/webjars/**")) { - String webjarsLocation = "classpath:/META-INF/resources/webjars/"; - if (this.resourceLoader.getResource(webjarsLocation).exists()) { - ResourceHandlerRegistration registration = registry.addResourceHandler("/webjars/**") - .addResourceLocations(webjarsLocation); - configureResourceCaching(registration); - customizeResourceHandlerRegistration(registration); - } + ResourceHandlerRegistration registration = registry.addResourceHandler("/webjars/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/"); + configureResourceCaching(registration); + customizeResourceHandlerRegistration(registration); } String staticPathPattern = this.webFluxProperties.getStaticPathPattern(); if (!registry.hasMappingForPattern(staticPathPattern)) { - List foundLocations = new ArrayList<>(); - for (String staticLocation : this.resourceProperties.getStaticLocations()) { - if (this.resourceLoader.getResource(staticLocation).exists()) { - foundLocations.add(staticLocation); - } - } - if (!foundLocations.isEmpty()) { - ResourceHandlerRegistration registration = registry.addResourceHandler(staticPathPattern) - .addResourceLocations(foundLocations.toArray(new String[0])); - configureResourceCaching(registration); - customizeResourceHandlerRegistration(registration); - } + ResourceHandlerRegistration registration = registry.addResourceHandler(staticPathPattern) + .addResourceLocations(this.resourceProperties.getStaticLocations()); + configureResourceCaching(registration); + customizeResourceHandlerRegistration(registration); } } 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 b6e8cd1b69..a919f42862 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 @@ -201,8 +201,6 @@ public class WebMvcAutoConfiguration { private final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer; - private final ResourceLoader resourceLoader; - private ServletContext servletContext; public WebMvcAutoConfigurationAdapter( @@ -211,7 +209,7 @@ public class WebMvcAutoConfiguration { ObjectProvider messageConvertersProvider, ObjectProvider resourceHandlerRegistrationCustomizerProvider, ObjectProvider dispatcherServletPath, - ObjectProvider> servletRegistrations, ResourceLoader resourceLoader) { + ObjectProvider> servletRegistrations) { this.resourceProperties = resourceProperties.hasBeenCustomized() ? resourceProperties : webProperties.getResources(); this.mvcProperties = mvcProperties; @@ -220,7 +218,6 @@ public class WebMvcAutoConfiguration { this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider.getIfAvailable(); this.dispatcherServletPath = dispatcherServletPath; this.servletRegistrations = servletRegistrations; - this.resourceLoader = resourceLoader; this.mvcProperties.checkConfiguration(); } @@ -337,11 +334,7 @@ public class WebMvcAutoConfiguration { logger.debug("Default resource handling disabled"); return; } - Resource webjarsLocationResource = this.resourceLoader - .getResource("classpath:/META-INF/resources/webjars/"); - if (webjarsLocationResource.exists()) { - addResourceHandler(registry, "/webjars/**", webjarsLocationResource); - } + addResourceHandler(registry, "/webjars/**", "classpath:/META-INF/resources/webjars/"); addResourceHandler(registry, this.mvcProperties.getStaticPathPattern(), (registration) -> { registration.addResourceLocations(this.resourceProperties.getStaticLocations()); if (this.servletContext != null) { @@ -351,7 +344,7 @@ public class WebMvcAutoConfiguration { }); } - private void addResourceHandler(ResourceHandlerRegistry registry, String pattern, Resource... locations) { + private void addResourceHandler(ResourceHandlerRegistry registry, String pattern, String... locations) { addResourceHandler(registry, pattern, (registration) -> registration.addResourceLocations(locations)); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java index 636844b2b4..18eacf1733 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java @@ -157,10 +157,9 @@ class WebFluxAutoConfigurationTests { SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class); assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**"); - assertThat(staticHandler).extracting("locationValues").asList().hasSize(2); - assertThat(staticHandler.getLocations()).hasSize(2); - assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [META-INF/resources/]"); - assertThat(staticHandler.getLocations().get(1)).hasToString("class path resource [public/]"); + assertThat(staticHandler).extracting("locationValues").asList().hasSize(4); + assertThat(staticHandler.getLocations()).hasSize(1); + assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [public/]"); assertThat(hm.getUrlMap().get("/webjars/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler webjarsHandler = (ResourceWebHandler) hm.getUrlMap().get("/webjars/**"); assertThat(webjarsHandler).extracting("locationValues").asList() @@ -174,7 +173,7 @@ class WebFluxAutoConfigurationTests { SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class); assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**"); - assertThat(staticHandler).extracting("locationValues").asList().hasSize(2); + assertThat(staticHandler).extracting("locationValues").asList().hasSize(4); }); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar b/spring-boot-project/spring-boot-autoconfigure/src/test/resources/META-INF/resources/webjars/webjar deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 32a02ce8f7..23aef8f021 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1663,7 +1663,7 @@ bom { ] } } - library("Spring Framework", "5.3.11") { + library("Spring Framework", "5.3.12-SNAPSHOT") { group("org.springframework") { imports = [ "spring-framework-bom"