Merge branch '1.5.x'

This commit is contained in:
Andy Wilkinson 2017-04-04 10:23:04 +01:00
commit 7f870aa19a
2 changed files with 14 additions and 3 deletions

View File

@ -305,7 +305,8 @@ public class WebMvcAutoConfiguration {
@Bean @Bean
public WelcomePageHandlerMapping welcomePageHandlerMapping( public WelcomePageHandlerMapping welcomePageHandlerMapping(
ResourceProperties resourceProperties) { ResourceProperties resourceProperties) {
return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage()); return new WelcomePageHandlerMapping(resourceProperties.getWelcomePage(),
this.mvcProperties.getStaticPathPattern());
} }
private void customizeResourceHandlerRegistration( private void customizeResourceHandlerRegistration(
@ -524,8 +525,9 @@ public class WebMvcAutoConfiguration {
private static final Log logger = LogFactory private static final Log logger = LogFactory
.getLog(WelcomePageHandlerMapping.class); .getLog(WelcomePageHandlerMapping.class);
private WelcomePageHandlerMapping(Resource welcomePage) { private WelcomePageHandlerMapping(Resource welcomePage,
if (welcomePage != null) { String staticPathPattern) {
if (welcomePage != null && "/**".equals(staticPathPattern)) {
logger.info("Adding welcome page: " + welcomePage); logger.info("Adding welcome page: " + welcomePage);
ParameterizableViewController controller = new ParameterizableViewController(); ParameterizableViewController controller = new ParameterizableViewController();
controller.setViewName("forward:index.html"); controller.setViewName("forward:index.html");

View File

@ -572,6 +572,15 @@ public class WebMvcAutoConfigurationTests {
.andExpect(status().isNotFound()); .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 @Test
public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() throws Exception { public void welcomePageMappingHandlesRequestsThatAcceptTextHtml() throws Exception {
load("spring.resources.static-locations:classpath:/welcome-page/"); load("spring.resources.static-locations:classpath:/welcome-page/");