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 fe03fd17618..c8156c4bcd9 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 @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -296,7 +296,8 @@ public class WebMvcAutoConfiguration { @Bean public WelcomePageHandlerMapping welcomePageHandlerMapping( ResourceProperties resourceProperties) { - return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage()); + return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage(), + this.mvcProperties.getStaticPathPattern()); } private void customizeResourceHandlerRegistration( @@ -505,8 +506,9 @@ public class WebMvcAutoConfiguration { private static final Log logger = LogFactory .getLog(WelcomePageHandlerMapping.class); - private WelcomePageHandlerMapping(Resource welcomePage) { - if (welcomePage != null) { + private WelcomePageHandlerMapping(Resource welcomePage, + String staticPathPattern) { + if (welcomePage != null && "/**".equals(staticPathPattern)) { logger.info("Adding welcome page: " + welcomePage); ParameterizableViewController controller = new ParameterizableViewController(); controller.setViewName("forward:index.html"); 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 25f9c18bbbb..fe00c76472a 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-2016 the original author or authors. + * Copyright 2012-2017 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. @@ -564,6 +564,15 @@ public class WebMvcAutoConfigurationTests { .andExpect(status().isNotFound()); } + @Test + public void welcomePageRootHandlerIsNotRegisteredWhenStaticPathPatternIsNotSlashStarStar() { + load("spring.resources.static-locations:classpath:/welcome-page/", + "spring.mvc.static-path-pattern:/foo/**"); + WelcomePageHandlerMapping welcomePageHandlerMapping = this.context + .getBean(WelcomePageHandlerMapping.class); + assertThat(welcomePageHandlerMapping.getRootHandler()).isNull(); + } + @Test public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() throws Exception { load("spring.resources.static-locations:classpath:/welcome-page/");