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
This commit is contained in:
parent
e60f26f8cc
commit
5fceb9d5b7
|
@ -50,7 +50,7 @@ public enum StaticResourceLocation {
|
|||
/**
|
||||
* The {@code "favicon.ico"} resource.
|
||||
*/
|
||||
FAVICON("/**/favicon.ico");
|
||||
FAVICON("/favicon.*", "/*/icon-*");
|
||||
|
||||
private final String[] patterns;
|
||||
|
||||
|
|
|
@ -128,8 +128,7 @@ public final class StaticResourceRequest {
|
|||
}
|
||||
|
||||
private Stream<String> getPatterns() {
|
||||
return this.locations.stream().flatMap(StaticResourceLocation::getPatterns)
|
||||
.map((pattern) -> pattern.replace("/**/", "/*/"));
|
||||
return this.locations.stream().flatMap(StaticResourceLocation::getPatterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -54,7 +54,9 @@ class StaticResourceRequestTests {
|
|||
assertMatcher(matcher).matches("/js/file.js");
|
||||
assertMatcher(matcher).matches("/images/file.css");
|
||||
assertMatcher(matcher).matches("/webjars/file.css");
|
||||
assertMatcher(matcher).matches("/foo/favicon.ico");
|
||||
assertMatcher(matcher).matches("/favicon.ico");
|
||||
assertMatcher(matcher).matches("/favicon.png");
|
||||
assertMatcher(matcher).matches("/icons/icon-48x48.png");
|
||||
assertMatcher(matcher).doesNotMatch("/bar");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
* Copyright 2012-2020 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.
|
||||
|
@ -48,7 +48,9 @@ class StaticResourceRequestTests {
|
|||
assertMatcher(matcher).matches("/js/file.js");
|
||||
assertMatcher(matcher).matches("/images/file.css");
|
||||
assertMatcher(matcher).matches("/webjars/file.css");
|
||||
assertMatcher(matcher).matches("/foo/favicon.ico");
|
||||
assertMatcher(matcher).matches("/favicon.ico");
|
||||
assertMatcher(matcher).matches("/favicon.png");
|
||||
assertMatcher(matcher).matches("/icons/icon-48x48.png");
|
||||
assertMatcher(matcher).doesNotMatch("/bar");
|
||||
}
|
||||
|
||||
|
|
|
@ -2639,13 +2639,6 @@ If either is found, it is automatically used as the welcome page of the applicat
|
|||
|
||||
|
||||
|
||||
[[boot-features-spring-mvc-favicon]]
|
||||
==== Custom Favicon
|
||||
As with other static resources, Spring Boot looks for a `favicon.ico` in the configured static content locations.
|
||||
If such a file is present, it is automatically used as the favicon of the application.
|
||||
|
||||
|
||||
|
||||
[[boot-features-spring-mvc-pathmatch]]
|
||||
==== Path Matching and Content Negotiation
|
||||
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).
|
||||
|
|
Loading…
Reference in New Issue