Commit 05e08960 authored by Andy Wilkinson's avatar Andy Wilkinson

Remove default favicon and support for serving from classpath root

Closes gh-17925
parent e03f822c
...@@ -332,27 +332,6 @@ public class WebMvcAutoConfiguration { ...@@ -332,27 +332,6 @@ public class WebMvcAutoConfiguration {
return new OrderedRequestContextFilter(); return new OrderedRequestContextFilter();
} }
@Configuration(proxyBeanMethods = false)
@ConditionalOnProperty(value = "spring.mvc.favicon.enabled", matchIfMissing = true)
public static class FaviconConfiguration implements WebMvcConfigurer {
private final ResourceProperties resourceProperties;
FaviconConfiguration(ResourceProperties resourceProperties) {
this.resourceProperties = resourceProperties;
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
if (!registry.hasMappingForPattern("favicon.ico")) {
registry.addResourceHandler("favicon.ico")
.addResourceLocations(this.resourceProperties.getStaticLocations())
.addResourceLocations("classpath:favicon.ico");
}
}
}
} }
/** /**
......
...@@ -699,12 +699,6 @@ ...@@ -699,12 +699,6 @@
"name": "spring.mustache.suffix", "name": "spring.mustache.suffix",
"defaultValue": ".mustache" "defaultValue": ".mustache"
}, },
{
"name": "spring.mvc.favicon.enabled",
"type": "java.lang.Boolean",
"description": "Whether to enable resolution of favicon.ico.",
"defaultValue": true
},
{ {
"name": "spring.mvc.formcontent.putfilter.enabled", "name": "spring.mvc.formcontent.putfilter.enabled",
"type": "java.lang.Boolean", "type": "java.lang.Boolean",
......
...@@ -196,7 +196,7 @@ class WebMvcAutoConfigurationTests { ...@@ -196,7 +196,7 @@ class WebMvcAutoConfigurationTests {
@Test @Test
void resourceHandlerMappingDisabled() { void resourceHandlerMappingDisabled() {
this.contextRunner.withPropertyValues("spring.resources.add-mappings:false") this.contextRunner.withPropertyValues("spring.resources.add-mappings:false")
.run((context) -> assertThat(getResourceMappingLocations(context)).hasSize(1)); .run((context) -> assertThat(getResourceMappingLocations(context)).hasSize(0));
} }
@Test @Test
...@@ -378,21 +378,6 @@ class WebMvcAutoConfigurationTests { ...@@ -378,21 +378,6 @@ class WebMvcAutoConfigurationTests {
.containsOnly("myViewResolver")); .containsOnly("myViewResolver"));
} }
@Test
void faviconMapping() {
this.contextRunner.run((context) -> {
List<Resource> favIconResources = getResourceMappingLocations(context).get("/favicon.ico");
assertThat(favIconResources.stream().map(ClassPathResource.class::cast).map(ClassPathResource::getPath))
.containsExactly("META-INF/resources/", "resources/", "static/", "public/", "favicon.ico");
});
}
@Test
void faviconMappingDisabled() {
this.contextRunner.withPropertyValues("spring.mvc.favicon.enabled:false")
.run((context) -> assertThat(getResourceMappingLocations(context).get("/favicon.ico")).isNull());
}
@Test @Test
void defaultAsyncRequestTimeout() { void defaultAsyncRequestTimeout() {
this.contextRunner.run((context) -> assertThat(ReflectionTestUtils this.contextRunner.run((context) -> assertThat(ReflectionTestUtils
...@@ -660,14 +645,12 @@ class WebMvcAutoConfigurationTests { ...@@ -660,14 +645,12 @@ class WebMvcAutoConfigurationTests {
private void assertCachePeriod(AssertableWebApplicationContext context) { private void assertCachePeriod(AssertableWebApplicationContext context) {
Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class)); Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class));
assertThat(handlerMap).hasSize(3); assertThat(handlerMap).hasSize(2);
for (Entry<String, Object> entry : handlerMap.entrySet()) { for (Entry<String, Object> entry : handlerMap.entrySet()) {
if (!entry.getKey().equals("/favicon.ico")) { Object handler = entry.getValue();
Object handler = entry.getValue(); if (handler instanceof ResourceHttpRequestHandler) {
if (handler instanceof ResourceHttpRequestHandler) { assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(5);
assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(5); assertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isNull();
assertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isNull();
}
} }
} }
} }
...@@ -784,7 +767,7 @@ class WebMvcAutoConfigurationTests { ...@@ -784,7 +767,7 @@ class WebMvcAutoConfigurationTests {
private void assertCacheControl(AssertableWebApplicationContext context) { private void assertCacheControl(AssertableWebApplicationContext context) {
Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class)); Map<String, Object> handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class));
assertThat(handlerMap).hasSize(3); assertThat(handlerMap).hasSize(2);
for (Object handler : handlerMap.keySet()) { for (Object handler : handlerMap.keySet()) {
if (handler instanceof ResourceHttpRequestHandler) { if (handler instanceof ResourceHttpRequestHandler) {
assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(-1); assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(-1);
...@@ -795,7 +778,12 @@ class WebMvcAutoConfigurationTests { ...@@ -795,7 +778,12 @@ class WebMvcAutoConfigurationTests {
} }
protected Map<String, List<Resource>> getResourceMappingLocations(ApplicationContext context) { protected Map<String, List<Resource>> getResourceMappingLocations(ApplicationContext context) {
return getMappingLocations(context.getBean("resourceHandlerMapping", HandlerMapping.class)); Object bean = context.getBean("resourceHandlerMapping");
if (bean instanceof HandlerMapping) {
return getMappingLocations(context.getBean("resourceHandlerMapping", HandlerMapping.class));
}
assertThat(bean.toString()).isEqualTo("null");
return Collections.emptyMap();
} }
protected List<ResourceResolver> getResourceResolvers(ApplicationContext context, String mapping) { protected List<ResourceResolver> getResourceResolvers(ApplicationContext context, String mapping) {
......
...@@ -2508,9 +2508,9 @@ welcome page of the application. ...@@ -2508,9 +2508,9 @@ welcome page of the application.
[[boot-features-spring-mvc-favicon]] [[boot-features-spring-mvc-favicon]]
==== Custom Favicon ==== Custom Favicon
Spring Boot looks for a `favicon.ico` in the configured static content locations and the As with other static resources, Spring Boot looks for a `favicon.ico` in the configured
root of the classpath (in that order). If such a file is present, it is automatically static content locations. If such a file is present, it is automatically used as the
used as the favicon of the application. favicon of the application.
[[boot-features-spring-mvc-pathmatch]] [[boot-features-spring-mvc-pathmatch]]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment