Skip to content

Commit 02b5773

Browse files
committed
Merge branch '2.4.x' into 2.5.x
2 parents f427ea5 + 0561992 commit 02b5773

File tree

5 files changed

+32
-22
lines changed

5 files changed

+32
-22
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/jersey/JerseyAutoConfigurationCustomFilterContextPathTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 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.

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
@@ -51,7 +51,6 @@
5151
import org.springframework.core.Ordered;
5252
import org.springframework.core.annotation.Order;
5353
import org.springframework.core.convert.ConversionService;
54-
import org.springframework.core.io.ClassPathResource;
5554
import org.springframework.format.Parser;
5655
import org.springframework.format.Printer;
5756
import org.springframework.format.support.FormattingConversionService;
@@ -158,12 +157,13 @@ void shouldRegisterResourceHandlerMapping() {
158157
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
159158
assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class);
160159
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**");
161-
assertThat(staticHandler.getLocations()).hasSize(4);
160+
assertThat(staticHandler).extracting("locationValues").asList().hasSize(4);
161+
assertThat(staticHandler.getLocations()).hasSize(1);
162+
assertThat(staticHandler.getLocations().get(0)).hasToString("class path resource [public/]");
162163
assertThat(hm.getUrlMap().get("/webjars/**")).isInstanceOf(ResourceWebHandler.class);
163164
ResourceWebHandler webjarsHandler = (ResourceWebHandler) hm.getUrlMap().get("/webjars/**");
164-
assertThat(webjarsHandler.getLocations()).hasSize(1);
165-
assertThat(webjarsHandler.getLocations().get(0))
166-
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
165+
assertThat(webjarsHandler).extracting("locationValues").asList()
166+
.containsExactly("classpath:/META-INF/resources/webjars/");
167167
});
168168
}
169169

@@ -173,7 +173,7 @@ void shouldMapResourcesToCustomPath() {
173173
SimpleUrlHandlerMapping hm = context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
174174
assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class);
175175
ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**");
176-
assertThat(staticHandler.getLocations()).hasSize(4);
176+
assertThat(staticHandler).extracting("locationValues").asList().hasSize(4);
177177
});
178178
}
179179

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;
@@ -177,8 +178,10 @@ void handlerMappingsCreated() {
177178
void resourceHandlerMapping() {
178179
this.contextRunner.run((context) -> {
179180
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
180-
assertThat(locations.get("/**")).hasSize(2);
181-
assertThat(locations.get("/webjars/**")).hasSize(0);
181+
assertThat(locations.get("/**")).hasSize(5);
182+
assertThat(locations.get("/webjars/**")).hasSize(1);
183+
assertThat(locations.get("/webjars/**").get(0))
184+
.isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
182185
assertThat(getResourceResolvers(context, "/webjars/**")).hasSize(1);
183186
assertThat(getResourceTransformers(context, "/webjars/**")).hasSize(0);
184187
assertThat(getResourceResolvers(context, "/**")).hasSize(1);
@@ -190,17 +193,17 @@ void resourceHandlerMapping() {
190193
void customResourceHandlerMapping() {
191194
this.contextRunner.withPropertyValues("spring.mvc.static-path-pattern:/static/**").run((context) -> {
192195
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
193-
assertThat(locations.get("/static/**")).hasSize(2);
196+
assertThat(locations.get("/static/**")).hasSize(5);
194197
assertThat(getResourceResolvers(context, "/static/**")).hasSize(1);
195198
});
196199
}
197200

198201
@Test
199202
void resourceHandlerMappingOverrideWebjars() {
200-
this.contextRunner.withUserConfiguration(WebJarsResources.class).run((context) -> {
203+
this.contextRunner.withUserConfiguration(WebJars.class).run((context) -> {
201204
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
202205
assertThat(locations.get("/webjars/**")).hasSize(1);
203-
assertThat(locations.get("/webjars/**").get(0).getFilename()).isEqualTo("test");
206+
assertThat(locations.get("/webjars/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
204207
});
205208
}
206209

@@ -209,7 +212,7 @@ void resourceHandlerMappingOverrideAll() {
209212
this.contextRunner.withUserConfiguration(AllResources.class).run((context) -> {
210213
Map<String, List<Resource>> locations = getResourceMappingLocations(context);
211214
assertThat(locations.get("/**")).hasSize(1);
212-
assertThat(locations.get("/**").get(0).getFilename()).isEqualTo("test");
215+
assertThat(locations.get("/**").get(0)).isEqualTo(new ClassPathResource("/foo/"));
213216
});
214217
}
215218

@@ -1039,7 +1042,7 @@ private void assertResourceHttpRequestHandler(AssertableWebApplicationContext co
10391042
protected Map<String, List<Resource>> getResourceMappingLocations(ApplicationContext context) {
10401043
Object bean = context.getBean("resourceHandlerMapping");
10411044
if (bean instanceof HandlerMapping) {
1042-
return getMappingLocations((HandlerMapping) bean);
1045+
return getMappingLocations(context, (HandlerMapping) bean);
10431046
}
10441047
assertThat(bean.toString()).isEqualTo("null");
10451048
return Collections.emptyMap();
@@ -1058,11 +1061,18 @@ protected List<ResourceTransformer> getResourceTransformers(ApplicationContext c
10581061
}
10591062

10601063
@SuppressWarnings("unchecked")
1061-
protected Map<String, List<Resource>> getMappingLocations(HandlerMapping mapping) {
1064+
private Map<String, List<Resource>> getMappingLocations(ApplicationContext context, HandlerMapping mapping) {
10621065
Map<String, List<Resource>> mappingLocations = new LinkedHashMap<>();
10631066
getHandlerMap(mapping).forEach((key, value) -> {
1064-
Object locations = ReflectionTestUtils.getField(value, "locationsToUse");
1065-
mappingLocations.put(key, (List<Resource>) locations);
1067+
List<String> locationValues = (List<String>) ReflectionTestUtils.getField(value, "locationValues");
1068+
List<Resource> locationResources = (List<Resource>) ReflectionTestUtils.getField(value,
1069+
"locationResources");
1070+
List<Resource> resources = new ArrayList<>();
1071+
for (String locationValue : locationValues) {
1072+
resources.add(context.getResource(locationValue));
1073+
}
1074+
resources.addAll(locationResources);
1075+
mappingLocations.put(key, resources);
10661076
});
10671077
return mappingLocations;
10681078
}
@@ -1093,11 +1103,11 @@ protected void renderMergedOutputModel(Map<String, Object> model, HttpServletReq
10931103
}
10941104

10951105
@Configuration(proxyBeanMethods = false)
1096-
static class WebJarsResources implements WebMvcConfigurer {
1106+
static class WebJars implements WebMvcConfigurer {
10971107

10981108
@Override
10991109
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1100-
registry.addResourceHandler("/webjars/**").addResourceLocations(new ClassPathResource("/test", getClass()));
1110+
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/foo/");
11011111
}
11021112

11031113
}
@@ -1107,7 +1117,7 @@ static class AllResources implements WebMvcConfigurer {
11071117

11081118
@Override
11091119
public void addResourceHandlers(ResourceHandlerRegistry registry) {
1110-
registry.addResourceHandler("/**").addResourceLocations(new ClassPathResource("/test", getClass()));
1120+
registry.addResourceHandler("/**").addResourceLocations("classpath:/foo/");
11111121
}
11121122

11131123
}

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)