Support multiple paths in DispatcherServletPathProvider
Closes gh-13603
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user