From d5554e0aa12fe5876f8f082396c775e0723252dd Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Mon, 25 Apr 2016 05:27:53 +0530 Subject: [PATCH 1/2] Use static-locations properties to locate favicon Closes gh-5751 --- .../boot/autoconfigure/web/ResourceProperties.java | 6 +++--- .../autoconfigure/web/WebMvcAutoConfigurationTests.java | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index a86bcc0b73..e2bae6c359 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -33,6 +33,7 @@ import org.springframework.core.io.ResourceLoader; * @author Phillip Webb * @author Brian Clozel * @author Dave Syer + * @author Venil Noronha * @since 1.1.0 */ @ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false) @@ -117,10 +118,9 @@ public class ResourceProperties implements ResourceLoaderAware { } List getFaviconLocations() { - List locations = new ArrayList( - CLASSPATH_RESOURCE_LOCATIONS.length + 1); + List locations = new ArrayList(staticLocations.length + 1); if (this.resourceLoader != null) { - for (String location : CLASSPATH_RESOURCE_LOCATIONS) { + for (String location : staticLocations) { locations.add(this.resourceLoader.getResource(location)); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index 410d638e38..7de728941e 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -412,7 +412,7 @@ public class WebMvcAutoConfigurationTests { assertThat(this.context.getBeansOfType(SimpleUrlHandlerMapping.class) .get("faviconHandlerMapping"), is(notNullValue())); Map> mappingLocations = getFaviconMappingLocations(); - assertThat(mappingLocations.get("/**/favicon.ico").size(), equalTo(5)); + assertThat(mappingLocations.get("/**/favicon.ico").size(), equalTo(6)); } @Test From ac8e87d79f329fe2ca834198854a648c49ee52f8 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 26 Apr 2016 09:24:37 +0200 Subject: [PATCH 2/2] Polish contribution Closes gh-5782 --- .../boot/autoconfigure/web/ResourceProperties.java | 4 ++-- .../autoconfigure/web/WebMvcAutoConfigurationTests.java | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java index e2bae6c359..db0e349ec2 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/ResourceProperties.java @@ -118,9 +118,9 @@ public class ResourceProperties implements ResourceLoaderAware { } List getFaviconLocations() { - List locations = new ArrayList(staticLocations.length + 1); + List locations = new ArrayList(this.staticLocations.length + 1); if (this.resourceLoader != null) { - for (String location : staticLocations) { + for (String location : this.staticLocations) { locations.add(this.resourceLoader.getResource(location)); } } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java index 7de728941e..acd2d82d05 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2016 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. @@ -415,6 +415,13 @@ public class WebMvcAutoConfigurationTests { assertThat(mappingLocations.get("/**/favicon.ico").size(), equalTo(6)); } + @Test + public void faviconMappingUsesStaticLocations() throws IllegalAccessException { + load("spring.resources.static-locations=classpath:/static"); + Map> mappingLocations = getFaviconMappingLocations(); + assertThat(mappingLocations.get("/**/favicon.ico").size(), equalTo(2)); + } + @Test public void faviconMappingDisabled() throws IllegalAccessException { load("spring.mvc.favicon.enabled:false");