diff --git a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java index 0f75bdaf4d..6933ce568e 100644 --- a/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java +++ b/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java @@ -17,7 +17,7 @@ package org.springframework.boot.autoconfigure.web; import java.io.IOException; -import java.util.Arrays; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Date; @@ -39,6 +39,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ResourceLoaderAware; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.Ordered; @@ -282,7 +283,9 @@ public class WebMvcAutoConfiguration { } @Configuration - public static class FaviconConfiguration { + public static class FaviconConfiguration implements ResourceLoaderAware { + + private ResourceLoader resourceLoader; @Bean public SimpleUrlHandlerMapping faviconHandlerMapping() { @@ -293,13 +296,28 @@ public class WebMvcAutoConfiguration { return mapping; } + @Override + public void setResourceLoader(ResourceLoader resourceLoader) { + this.resourceLoader = resourceLoader; + } + @Bean public ResourceHttpRequestHandler faviconRequestHandler() { ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler(); - requestHandler.setLocations(Arrays - . asList(new ClassPathResource("/"))); + requestHandler.setLocations(getLocations()); return requestHandler; } + + private List getLocations() { + List locations = new ArrayList( + CLASSPATH_RESOURCE_LOCATIONS.length + 1); + for (String location : CLASSPATH_RESOURCE_LOCATIONS) { + locations.add(this.resourceLoader.getResource(location)); + } + locations.add(new ClassPathResource("/")); + return Collections.unmodifiableList(locations); + } + } } diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/favicon.ico b/spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/favicon.ico similarity index 100% rename from spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/favicon.ico rename to spring-boot-samples/spring-boot-sample-web-ui/src/main/resources/static/favicon.ico