Commit 220f8cdc authored by Brian Clozel's avatar Brian Clozel

Order WelcomePageHandlerMapping at lower precedence

This commit orders the `WelcomePageHandlerMapping` at
`Ordered.LOWEST_PRECEDENCE -1` in order to give a chance to other
mappings to handle the incoming requests.

In this case, developers might provide a custom `ViewController` or
custom `HandlerMapping` for the `"/"` path and we should not override
that opinion.

Closes gh-12335
parent 5320081d
......@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders;
import org.springframework.context.ApplicationContext;
import org.springframework.core.Ordered;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
......@@ -74,7 +75,7 @@ final class WelcomePageHandlerMapping extends AbstractUrlHandlerMapping {
ParameterizableViewController controller = new ParameterizableViewController();
controller.setViewName(viewName);
setRootHandler(controller);
setOrder(0);
setOrder(Ordered.LOWEST_PRECEDENCE - 1);
}
@Override
......
......@@ -35,6 +35,7 @@ import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
......@@ -62,6 +63,15 @@ public class WelcomePageHandlerMappingTests {
.withUserConfiguration(HandlerMappingConfiguration.class).withConfiguration(
AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class));
@Test
public void isOrderedAtLowPriority() {
this.contextRunner.withUserConfiguration(StaticResourceConfiguration.class)
.run((context) -> {
WelcomePageHandlerMapping handler = context.getBean(WelcomePageHandlerMapping.class);
assertThat(handler.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 1);
});
}
@Test
public void handlesRequestForStaticPageThatAcceptsTextHtml() {
this.contextRunner.withUserConfiguration(StaticResourceConfiguration.class)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment