From 05e089601e9838a15cd1d083be76aea276b9df78 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 22 Aug 2019 13:53:13 +0100 Subject: [PATCH] Remove default favicon and support for serving from classpath root Closes gh-17925 --- .../web/servlet/WebMvcAutoConfiguration.java | 21 ---------- ...itional-spring-configuration-metadata.json | 6 --- .../servlet/WebMvcAutoConfigurationTests.java | 38 ++++++------------ .../main/asciidoc/spring-boot-features.adoc | 6 +-- .../src/main/resources/favicon.ico | Bin 946 -> 0 bytes 5 files changed, 16 insertions(+), 55 deletions(-) delete mode 100644 spring-boot-project/spring-boot/src/main/resources/favicon.ico diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 5a5e3f8cf6..36676cc9c0 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -332,27 +332,6 @@ public class WebMvcAutoConfiguration { 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"); - } - } - - } - } /** diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json index 1fe8ef7257..fcf5a61953 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json @@ -699,12 +699,6 @@ "name": "spring.mustache.suffix", "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", "type": "java.lang.Boolean", diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 7d0510898f..6f7159ba0f 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -196,7 +196,7 @@ class WebMvcAutoConfigurationTests { @Test void resourceHandlerMappingDisabled() { this.contextRunner.withPropertyValues("spring.resources.add-mappings:false") - .run((context) -> assertThat(getResourceMappingLocations(context)).hasSize(1)); + .run((context) -> assertThat(getResourceMappingLocations(context)).hasSize(0)); } @Test @@ -378,21 +378,6 @@ class WebMvcAutoConfigurationTests { .containsOnly("myViewResolver")); } - @Test - void faviconMapping() { - this.contextRunner.run((context) -> { - List 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 void defaultAsyncRequestTimeout() { this.contextRunner.run((context) -> assertThat(ReflectionTestUtils @@ -660,14 +645,12 @@ class WebMvcAutoConfigurationTests { private void assertCachePeriod(AssertableWebApplicationContext context) { Map handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class)); - assertThat(handlerMap).hasSize(3); + assertThat(handlerMap).hasSize(2); for (Entry entry : handlerMap.entrySet()) { - if (!entry.getKey().equals("/favicon.ico")) { - Object handler = entry.getValue(); - if (handler instanceof ResourceHttpRequestHandler) { - assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(5); - assertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isNull(); - } + Object handler = entry.getValue(); + if (handler instanceof ResourceHttpRequestHandler) { + assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(5); + assertThat(((ResourceHttpRequestHandler) handler).getCacheControl()).isNull(); } } } @@ -784,7 +767,7 @@ class WebMvcAutoConfigurationTests { private void assertCacheControl(AssertableWebApplicationContext context) { Map handlerMap = getHandlerMap(context.getBean("resourceHandlerMapping", HandlerMapping.class)); - assertThat(handlerMap).hasSize(3); + assertThat(handlerMap).hasSize(2); for (Object handler : handlerMap.keySet()) { if (handler instanceof ResourceHttpRequestHandler) { assertThat(((ResourceHttpRequestHandler) handler).getCacheSeconds()).isEqualTo(-1); @@ -795,7 +778,12 @@ class WebMvcAutoConfigurationTests { } protected Map> 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 getResourceResolvers(ApplicationContext context, String mapping) { diff --git a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc index e8471d9774..684b802549 100644 --- a/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc @@ -2508,9 +2508,9 @@ welcome page of the application. [[boot-features-spring-mvc-favicon]] ==== Custom Favicon -Spring Boot looks for a `favicon.ico` in the configured static content locations and the -root of the classpath (in that order). If such a file is present, it is automatically -used as the favicon of the application. +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]] diff --git a/spring-boot-project/spring-boot/src/main/resources/favicon.ico b/spring-boot-project/spring-boot/src/main/resources/favicon.ico deleted file mode 100644 index e5a293420da31e952b5d47660a089cee51c008e8..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 946 zcma)3O=}ZT6n*u3BXlKFT-eFXWSS<8PDNu2+6JlJbyvlW=%O24)K;WLDk+!>BGfNj zgc2)8v^I(qD_ALQGc(B~cIM5DsGBZaC?fuWVs)7(4(}VkZCQsdp&)(?oE-m!Mt)=swRKI%I$=_{v zj7-?pGpduH?)1#j-Vdb+YHX|2Ig+}dM#tkDtz#V!O7?OY-A2u_6r{D{Y34&Y1+T`cO#b+STOhD+~Sx}}1LDXM^Kn<=T zqK_`G*n>K2OfP_Q4yKPahppp34dl&1@c9HN=^+rcxlJGKPCkqL(trH24$Bo@ZQ*iT@hP%nRl+k&eev`{otLX z|FGZ<7j`?wmt$k*F=ekpsE+Zj z4qo+5!kW6ZwiyC