Skip to content

Commit 76c9306

Browse files
committed
Adjust logging of resource locations
1 parent 0853baa commit 76c9306

File tree

2 files changed

+25
-29
lines changed

2 files changed

+25
-29
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/resource/ResourceWebHandler.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,6 @@ public void setUseLastModified(boolean useLastModified) {
304304
public void afterPropertiesSet() throws Exception {
305305
resolveResourceLocations();
306306

307-
if (logger.isWarnEnabled() && CollectionUtils.isEmpty(getLocations())) {
308-
logger.warn("Locations list is empty. No resources will be served unless a " +
309-
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
310-
}
311-
312307
if (this.resourceResolvers.isEmpty()) {
313308
this.resourceResolvers.add(new PathResourceResolver());
314309
}
@@ -341,6 +336,12 @@ private void resolveResourceLocations() {
341336

342337
this.locationsToUse.clear();
343338
this.locationsToUse.addAll(result);
339+
340+
if (logger.isInfoEnabled()) {
341+
logger.info(!this.locationsToUse.isEmpty() ?
342+
"Locations in use: " + locationToString(this.locationsToUse) :
343+
"0 locations in use.");
344+
}
344345
}
345346

346347
/**
@@ -350,10 +351,6 @@ private void resolveResourceLocations() {
350351
*/
351352
protected void initAllowedLocations() {
352353
if (CollectionUtils.isEmpty(getLocations())) {
353-
if (logger.isInfoEnabled()) {
354-
logger.info("Locations list is empty. No resources will be served unless a " +
355-
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
356-
}
357354
return;
358355
}
359356
for (int i = getResourceResolvers().size() - 1; i >= 0; i--) {
@@ -621,18 +618,13 @@ protected void setHeaders(ServerWebExchange exchange, Resource resource, @Nullab
621618

622619
@Override
623620
public String toString() {
624-
return "ResourceWebHandler " + formatLocations();
621+
return "ResourceWebHandler " + locationToString(getLocations());
625622
}
626623

627-
private Object formatLocations() {
628-
if (!this.locationValues.isEmpty()) {
629-
return this.locationValues.stream().collect(Collectors.joining("\", \"", "[\"", "\"]"));
630-
}
631-
if (!getLocations().isEmpty()) {
632-
return "[" + getLocations().toString()
633-
.replaceAll("class path resource", "Classpath")
634-
.replaceAll("ServletContext resource", "ServletContext") + "]";
635-
}
636-
return Collections.emptyList();
624+
private String locationToString(List<Resource> locations) {
625+
return locations.toString()
626+
.replaceAll("class path resource", "classpath")
627+
.replaceAll("ServletContext resource", "ServletContext");
637628
}
629+
638630
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,6 @@ public void setUseLastModified(boolean useLastModified) {
392392
public void afterPropertiesSet() throws Exception {
393393
resolveResourceLocations();
394394

395-
if (logger.isWarnEnabled() && CollectionUtils.isEmpty(getLocations())) {
396-
logger.warn("Locations list is empty. No resources will be served unless a " +
397-
"custom ResourceResolver is configured as an alternative to PathResourceResolver.");
398-
}
399-
400395
if (this.resourceResolvers.isEmpty()) {
401396
this.resourceResolvers.add(new PathResourceResolver());
402397
}
@@ -472,6 +467,12 @@ private void resolveResourceLocations() {
472467

473468
this.locationsToUse.clear();
474469
this.locationsToUse.addAll(result);
470+
471+
if (logger.isInfoEnabled()) {
472+
logger.info(!this.locationsToUse.isEmpty() ?
473+
"Locations in use: " + locationToString(this.locationsToUse) :
474+
"0 locations in use.");
475+
}
475476
}
476477

477478
/**
@@ -810,10 +811,13 @@ protected void setHeaders(HttpServletResponse response, Resource resource, @Null
810811

811812
@Override
812813
public String toString() {
813-
return "ResourceHttpRequestHandler " +
814-
getLocations().toString()
815-
.replaceAll("class path resource", "Classpath")
816-
.replaceAll("ServletContext resource", "ServletContext");
814+
return "ResourceHttpRequestHandler " + locationToString(getLocations());
815+
}
816+
817+
private String locationToString(List<Resource> locations) {
818+
return locations.toString()
819+
.replaceAll("class path resource", "classpath")
820+
.replaceAll("ServletContext resource", "ServletContext");
817821
}
818822

819823
}

0 commit comments

Comments
 (0)