Skip to content

Commit 5fceb9d

Browse files
committed
Change favicon StaticResourceLocation
Prior to this commit, the `StaticResourceLocation` for favicons would point to `"/**/favicon.ico"`. This location does not reflect the current web development landscape, since the png format and size variants are not supported here. Also, the `"**"` pattern can be costly at runtime and is deprecated by the new path pattern support in Spring Framework (see gh-22833). This commit changes the default locations to `"/favicon.*","/*/icon-*"`, supporting common use cases such as `"/favicon.ico"`, `"/favicon.png"` and `"/icons/icon-48x48.png"`. Closes gh-23126
1 parent e60f26f commit 5fceb9d

File tree

5 files changed

+10
-14
lines changed

5 files changed

+10
-14
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/StaticResourceLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public enum StaticResourceLocation {
5050
/**
5151
* The {@code "favicon.ico"} resource.
5252
*/
53-
FAVICON("/**/favicon.ico");
53+
FAVICON("/favicon.*", "/*/icon-*");
5454

5555
private final String[] patterns;
5656

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ private List<ServerWebExchangeMatcher> getDelegateMatchers() {
128128
}
129129

130130
private Stream<String> getPatterns() {
131-
return this.locations.stream().flatMap(StaticResourceLocation::getPatterns)
132-
.map((pattern) -> pattern.replace("/**/", "/*/"));
131+
return this.locations.stream().flatMap(StaticResourceLocation::getPatterns);
133132
}
134133

135134
@Override

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/reactive/StaticResourceRequestTests.java

Lines changed: 4 additions & 2 deletions
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-2020 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.
@@ -54,7 +54,9 @@ void atCommonLocationsShouldMatchCommonLocations() {
5454
assertMatcher(matcher).matches("/js/file.js");
5555
assertMatcher(matcher).matches("/images/file.css");
5656
assertMatcher(matcher).matches("/webjars/file.css");
57-
assertMatcher(matcher).matches("/foo/favicon.ico");
57+
assertMatcher(matcher).matches("/favicon.ico");
58+
assertMatcher(matcher).matches("/favicon.png");
59+
assertMatcher(matcher).matches("/icons/icon-48x48.png");
5860
assertMatcher(matcher).doesNotMatch("/bar");
5961
}
6062

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/StaticResourceRequestTests.java

Lines changed: 4 additions & 2 deletions
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-2020 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.
@@ -48,7 +48,9 @@ void atCommonLocationsShouldMatchCommonLocations() {
4848
assertMatcher(matcher).matches("/js/file.js");
4949
assertMatcher(matcher).matches("/images/file.css");
5050
assertMatcher(matcher).matches("/webjars/file.css");
51-
assertMatcher(matcher).matches("/foo/favicon.ico");
51+
assertMatcher(matcher).matches("/favicon.ico");
52+
assertMatcher(matcher).matches("/favicon.png");
53+
assertMatcher(matcher).matches("/icons/icon-48x48.png");
5254
assertMatcher(matcher).doesNotMatch("/bar");
5355
}
5456

spring-boot-project/spring-boot-docs/src/docs/asciidoc/spring-boot-features.adoc

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2639,13 +2639,6 @@ If either is found, it is automatically used as the welcome page of the applicat
26392639

26402640

26412641

2642-
[[boot-features-spring-mvc-favicon]]
2643-
==== Custom Favicon
2644-
As with other static resources, Spring Boot looks for a `favicon.ico` in the configured static content locations.
2645-
If such a file is present, it is automatically used as the favicon of the application.
2646-
2647-
2648-
26492642
[[boot-features-spring-mvc-pathmatch]]
26502643
==== Path Matching and Content Negotiation
26512644
Spring MVC can map incoming HTTP requests to handlers by looking at the request path and matching it to the mappings defined in your application (for example, `@GetMapping` annotations on Controller methods).

0 commit comments

Comments
 (0)