Skip to content

Commit 94e9c94

Browse files
committed
Merge branch '1.4.x' into 1.5.x
2 parents 4d71bfb + b280e30 commit 94e9c94

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
300300
@Bean
301301
public WelcomePageHandlerMapping welcomePageHandlerMapping(
302302
ResourceProperties resourceProperties) {
303-
return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage());
303+
return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage(),
304+
this.mvcProperties.getStaticPathPattern());
304305
}
305306

306307
private void customizeResourceHandlerRegistration(
@@ -520,8 +521,9 @@ static final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
520521
private static final Log logger = LogFactory
521522
.getLog(WelcomePageHandlerMapping.class);
522523

523-
private WelcomePageHandlerMapping(Resource welcomePage) {
524-
if (welcomePage != null) {
524+
private WelcomePageHandlerMapping(Resource welcomePage,
525+
String staticPathPattern) {
526+
if (welcomePage != null && "/**".equals(staticPathPattern)) {
525527
logger.info("Adding welcome page: " + welcomePage);
526528
ParameterizableViewController controller = new ParameterizableViewController();
527529
controller.setViewName("forward:index.html");

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/WebMvcAutoConfigurationTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,15 @@ public void welcomePageMappingProducesNotFoundResponseWhenThereIsNoWelcomePage()
569569
.andExpect(status().isNotFound());
570570
}
571571

572+
@Test
573+
public void welcomePageRootHandlerIsNotRegisteredWhenStaticPathPatternIsNotSlashStarStar() {
574+
load("spring.resources.static-locations:classpath:/welcome-page/",
575+
"spring.mvc.static-path-pattern:/foo/**");
576+
WelcomePageHandlerMapping welcomePageHandlerMapping = this.context
577+
.getBean(WelcomePageHandlerMapping.class);
578+
assertThat(welcomePageHandlerMapping.getRootHandler()).isNull();
579+
}
580+
572581
@Test
573582
public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() throws Exception {
574583
load("spring.resources.static-locations:classpath:/welcome-page/");

0 commit comments

Comments
 (0)