Support multiple paths in DispatcherServletPathProvider

Closes gh-13603
This commit is contained in:
Madhura Bhave
2018-06-28 11:57:19 -07:00
parent 43ea78f2ce
commit fddc9e9c7e
11 changed files with 198 additions and 74 deletions

View File

@@ -17,6 +17,7 @@
package org.springframework.boot.autoconfigure.web.servlet;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import javax.servlet.MultipartConfigElement;
@@ -160,8 +161,9 @@ public class DispatcherServletAutoConfiguration {
@ConditionalOnMissingBean(DispatcherServletPathProvider.class)
@ConditionalOnSingleCandidate(DispatcherServlet.class)
public DispatcherServletPathProvider dispatcherServletPathProvider() {
return () -> DispatcherServletRegistrationConfiguration.this.serverProperties
.getServlet().getPath();
return () -> Collections.singleton(
DispatcherServletRegistrationConfiguration.this.serverProperties
.getServlet().getPath());
}
}

View File

@@ -16,11 +16,13 @@
package org.springframework.boot.autoconfigure.web.servlet;
import java.util.Set;
import org.springframework.web.servlet.DispatcherServlet;
/**
* Interface that provides the path of the {@link DispatcherServlet} in an application
* context.
* Interface that provides the paths that the {@link DispatcherServlet} in an application
* context is mapped to.
*
* @author Madhura Bhave
* @since 2.0.2
@@ -28,6 +30,6 @@ import org.springframework.web.servlet.DispatcherServlet;
@FunctionalInterface
public interface DispatcherServletPathProvider {
String getServletPath();
Set<String> getServletPaths();
}

View File

@@ -112,7 +112,7 @@ public class DispatcherServletAutoConfigurationTests {
.containsExactly("/spring/*");
assertThat(registration.getMultipartConfig()).isNull();
assertThat(context.getBean(DispatcherServletPathProvider.class)
.getServletPath()).isEqualTo("/spring");
.getServletPaths()).containsExactly("/spring");
});
}
@@ -129,8 +129,8 @@ public class DispatcherServletAutoConfigurationTests {
this.contextRunner.withUserConfiguration(CustomDispatcherServletSameName.class)
.withPropertyValues("server.servlet.path:/spring")
.run((context) -> assertThat(context
.getBean(DispatcherServletPathProvider.class).getServletPath())
.isEqualTo("/spring"));
.getBean(DispatcherServletPathProvider.class).getServletPaths())
.containsExactly("/spring"));
}
@Test