diff --git a/buildSrc/src/main/java/org/springframework/boot/build/SyncAppSource.java b/buildSrc/src/main/java/org/springframework/boot/build/SyncAppSource.java index 1a8204805c5..9d274b81157 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/SyncAppSource.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/SyncAppSource.java @@ -1,5 +1,5 @@ /* - * Copyright 2021 the original author or authors. + * Copyright 2021-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. 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 e3af2141ea2..59edb80ea7b 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 @@ -52,7 +52,6 @@ import org.springframework.context.i18n.LocaleContext; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.core.convert.ConversionService; -import org.springframework.core.io.ClassPathResource; import org.springframework.format.Parser; import org.springframework.format.Printer; import org.springframework.format.support.FormattingConversionService; @@ -161,12 +160,13 @@ class WebFluxAutoConfigurationTests { SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class); assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class); ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**"); - assertThat(staticHandler.getLocations()).hasSize(4); + 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.getLocations()).hasSize(1); - assertThat(webjarsHandler.getLocations().get(0)) - .isEqualTo(new ClassPathResource("/META-INF/resources/webjars/")); + assertThat(webjarsHandler).extracting("locationValues").asList() + .containsExactly("classpath:/META-INF/resources/webjars/"); }); } @@ -176,7 +176,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.getLocations()).hasSize(4); + assertThat(staticHandler).extracting("locationValues").asList().hasSize(4); }); } 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 3b9d06d2680..2e50b5ce392 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 @@ -22,6 +22,7 @@ import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.time.format.FormatStyle; +import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.LinkedHashMap; @@ -175,8 +176,10 @@ class WebMvcAutoConfigurationTests { void resourceHandlerMapping() { this.contextRunner.run((context) -> { Map> locations = getResourceMappingLocations(context); - assertThat(locations.get("/**")).hasSize(2); - assertThat(locations.get("/webjars/**")).hasSize(0); + assertThat(locations.get("/**")).hasSize(5); + assertThat(locations.get("/webjars/**")).hasSize(1); + assertThat(locations.get("/webjars/**").get(0)) + .isEqualTo(new ClassPathResource("/META-INF/resources/webjars/")); assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1); assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0); assertThat(getResourceResolvers(context, "/**")).hasSize(1); @@ -188,17 +191,17 @@ class WebMvcAutoConfigurationTests { void customResourceHandlerMapping() { this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**").run((context) -> { Map> locations = getResourceMappingLocations(context); - assertThat(locations.get("/static/**")).hasSize(2); + assertThat(locations.get("/static/**")).hasSize(5); assertThat(getResourceResolvers(context, "/static/**")).hasSize(1); }); } @Test void resourceHandlerMappingOverrideWebjars() { - this.contextRunner.withUserConfiguration(WebJarsResources.class).run((context) -> { + this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> { Map> locations = getResourceMappingLocations(context); assertThat(locations.get("/webjars/**")).hasSize(1); - assertThat(locations.get("/webjars/**").get(0).getFilename()).isEqualTo("test"); + assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/")); }); } @@ -207,7 +210,7 @@ class WebMvcAutoConfigurationTests { this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> { Map> locations = getResourceMappingLocations(context); assertThat(locations.get("/**")).hasSize(1); - assertThat(locations.get("/**").get(0).getFilename()).isEqualTo("test"); + assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/")); }); } @@ -1024,7 +1027,7 @@ class WebMvcAutoConfigurationTests { protected Map> getResourceMappingLocations(ApplicationContext context) { Object bean = context.getBean("resourceHandlerMapping"); if (bean instanceof HandlerMapping) { - return getMappingLocations((HandlerMapping) bean); + return getMappingLocations(context, (HandlerMapping) bean); } assertThat(bean.toString()).isEqualTo("null"); return Collections.emptyMap(); @@ -1043,11 +1046,18 @@ class WebMvcAutoConfigurationTests { } @SuppressWarnings("unchecked") - protected Map> getMappingLocations(HandlerMapping mapping) { + private Map> getMappingLocations(ApplicationContext context, HandlerMapping mapping) { Map> mappingLocations = new LinkedHashMap<>(); getHandlerMap(mapping).forEach((key, value) -> { - Object locations = ReflectionTestUtils.getField(value, "locationsToUse"); - mappingLocations.put(key, (List) locations); + List locationValues = (List) ReflectionTestUtils.getField(value, "locationValues"); + List locationResources = (List) ReflectionTestUtils.getField(value, + "locationResources"); + List resources = new ArrayList<>(); + for (String locationValue : locationValues) { + resources.add(context.getResource(locationValue)); + } + resources.addAll(locationResources); + mappingLocations.put(key, resources); }); return mappingLocations; } @@ -1078,11 +1088,11 @@ class WebMvcAutoConfigurationTests { } @Configuration(proxyBeanMethods = false) - static class WebJarsResources implements WebMvcConfigurer { + static class WebJars implements WebMvcConfigurer { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/webjars/**").addResourceLocations(new ClassPathResource("/test", getClass())); + registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/foo/"); } } @@ -1092,7 +1102,7 @@ class WebMvcAutoConfigurationTests { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("/**").addResourceLocations(new ClassPathResource("/test", getClass())); + registry.addResourceHandler("/**").addResourceLocations("classpath:/foo/"); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java index cbd19bbe4a9..bbde4c7121c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License.