Skip to content

Commit 2034ad4

Browse files
committed
Merge branch '2.5.x'
2 parents 9514a72 + 02b5773 commit 2034ad4

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

buildSrc/src/main/java/org/springframework/boot/build/SyncAppSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2021 the original author or authors.
2+
* Copyright 2021-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/reactive/WebFluxAutoConfigurationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
import org.springframework.core.Ordered;
5353
import org.springframework.core.annotation.Order;
5454
import org.springframework.core.convert.ConversionService;
55-
import org.springframework.core.io.ClassPathResource;
5655
import org.springframework.format.Parser;
5756
import org.springframework.format.Printer;
5857
import org.springframework.format.support.FormattingConversionService;
@@ -161,12 +160,13 @@ void shouldRegisterResourceHandlerMapping() {
161160
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
162161
assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class);
163162
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**");
164-
assertThat(staticHandler.getLocations()).hasSize(4);
163+
assertThat(staticHandler).extracting("locationValues").asList().hasSize(4);
164+
assertThat(staticHandler.getLocations()).hasSize(1);
165+
assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [public/]");
165166
assertThat(hm.getUrlMap().get("/webjars/**")).isInstanceOf(ResourceWebHandler.class);
166167
ResourceWebHandler webjarsHandler = (ResourceWebHandler) hm.getUrlMap().get("/webjars/**");
167-
assertThat(webjarsHandler.getLocations()).hasSize(1);
168-
assertThat(webjarsHandler.getLocations().get(0))
169-
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
168+
assertThat(webjarsHandler).extracting("locationValues").asList()
169+
.containsExactly("classpath:/META-INF/resources/webjars/");
170170
});
171171
}
172172

@@ -176,7 +176,7 @@ void shouldMapResourcesToCustomPath() {
176176
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
177177
assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class);
178178
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**");
179-
assertThat(staticHandler.getLocations()).hasSize(4);
179+
assertThat(staticHandler).extracting("locationValues").asList().hasSize(4);
180180
});
181181
}
182182

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.ZonedDateTime;
2323
import java.time.format.DateTimeFormatter;
2424
import java.time.format.FormatStyle;
25+
import java.util.ArrayList;
2526
import java.util.Collections;
2627
import java.util.Date;
2728
import java.util.LinkedHashMap;
@@ -175,8 +176,10 @@ void handlerMappingsCreated() {
175176
void resourceHandlerMapping() {
176177
this.contextRunner.run((context) -> {
177178
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
178-
assertThat(locations.get("/**")).hasSize(2);
179-
assertThat(locations.get("/webjars/**")).hasSize(0);
179+
assertThat(locations.get("/**")).hasSize(5);
180+
assertThat(locations.get("/webjars/**")).hasSize(1);
181+
assertThat(locations.get("/webjars/**").get(0))
182+
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
180183
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1);
181184
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0);
182185
assertThat(getResourceResolvers(context, "/**")).hasSize(1);
@@ -188,17 +191,17 @@ void resourceHandlerMapping() {
188191
void customResourceHandlerMapping() {
189192
this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**").run((context) -> {
190193
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
191-
assertThat(locations.get("/static/**")).hasSize(2);
194+
assertThat(locations.get("/static/**")).hasSize(5);
192195
assertThat(getResourceResolvers(context, "/static/**")).hasSize(1);
193196
});
194197
}
195198

196199
@Test
197200
void resourceHandlerMappingOverrideWebjars() {
198-
this.contextRunner.withUserConfiguration(WebJarsResources.class).run((context) -> {
201+
this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> {
199202
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
200203
assertThat(locations.get("/webjars/**")).hasSize(1);
201-
assertThat(locations.get("/webjars/**").get(0).getFilename()).isEqualTo("test");
204+
assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
202205
});
203206
}
204207

@@ -207,7 +210,7 @@ void resourceHandlerMappingOverrideAll() {
207210
this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> {
208211
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
209212
assertThat(locations.get("/**")).hasSize(1);
210-
assertThat(locations.get("/**").get(0).getFilename()).isEqualTo("test");
213+
assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
211214
});
212215
}
213216

@@ -1024,7 +1027,7 @@ private void assertResourceHttpRequestHandler(AssertableWebApplicationContext co
10241027
protected Map<String, List<Resource>> getResourceMappingLocations(ApplicationContext context) {
10251028
Object bean = context.getBean("resourceHandlerMapping");
10261029
if (bean instanceof HandlerMapping) {
1027-
return getMappingLocations((HandlerMapping) bean);
1030+
return getMappingLocations(context, (HandlerMapping) bean);
10281031
}
10291032
assertThat(bean.toString()).isEqualTo("null");
10301033
return Collections.emptyMap();
@@ -1043,11 +1046,18 @@ protected List<ResourceTransformer> getResourceTransformers(ApplicationContext c
10431046
}
10441047

10451048
@SuppressWarnings("unchecked")
1046-
protected Map<String, List<Resource>> getMappingLocations(HandlerMapping mapping) {
1049+
private Map<String, List<Resource>> getMappingLocations(ApplicationContext context, HandlerMapping mapping) {
10471050
Map<String, List<Resource>> mappingLocations = new LinkedHashMap<>();
10481051
getHandlerMap(mapping).forEach((key, value) -> {
1049-
Object locations = ReflectionTestUtils.getField(value, "locationsToUse");
1050-
mappingLocations.put(key, (List<Resource>) locations);
1052+
List<String> locationValues = (List<String>) ReflectionTestUtils.getField(value, "locationValues");
1053+
List<Resource> locationResources = (List<Resource>) ReflectionTestUtils.getField(value,
1054+
"locationResources");
1055+
List<Resource> resources = new ArrayList<>();
1056+
for (String locationValue : locationValues) {
1057+
resources.add(context.getResource(locationValue));
1058+
}
1059+
resources.addAll(locationResources);
1060+
mappingLocations.put(key, resources);
10511061
});
10521062
return mappingLocations;
10531063
}
@@ -1078,11 +1088,11 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
10781088
}
10791089

10801090
@Configuration(proxyBeanMethods = false)
1081-
static class WebJarsResources implements WebMvcConfigurer {
1091+
static class WebJars implements WebMvcConfigurer {
10821092

10831093
@Override
10841094
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1085-
registry.addResourceHandler("/webjars/**").addResourceLocations(new ClassPathResource("/test", getClass()));
1095+
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/foo/");
10861096
}
10871097

10881098
}
@@ -1092,7 +1102,7 @@ static class AllResources implements WebMvcConfigurer {
10921102

10931103
@Override
10941104
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1095-
registry.addResourceHandler("/**").addResourceLocations(new ClassPathResource("/test", getClass()));
1105+
registry.addResourceHandler("/**").addResourceLocations("classpath:/foo/");
10961106
}
10971107

10981108
}

spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConstructorBinding.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)