|
56 | 56 | import org.springframework.boot.autoconfigure.web.servlet.WebMvcProperties.Format;
|
57 | 57 | import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
58 | 58 | import org.springframework.boot.convert.ApplicationConversionService;
|
| 59 | +import org.springframework.boot.web.servlet.ServletRegistrationBean; |
59 | 60 | import org.springframework.boot.web.servlet.filter.OrderedFormContentFilter;
|
60 | 61 | import org.springframework.boot.web.servlet.filter.OrderedHiddenHttpMethodFilter;
|
61 | 62 | import org.springframework.boot.web.servlet.filter.OrderedRequestContextFilter;
|
@@ -191,18 +192,22 @@ public static class WebMvcAutoConfigurationAdapter implements WebMvcConfigurer {
|
191 | 192 |
|
192 | 193 | private final ObjectProvider<DispatcherServletPath> dispatcherServletPath;
|
193 | 194 |
|
| 195 | + private final ObjectProvider<ServletRegistrationBean<?>> servletRegistrations; |
| 196 | + |
194 | 197 | final ResourceHandlerRegistrationCustomizer resourceHandlerRegistrationCustomizer;
|
195 | 198 |
|
196 | 199 | public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties, WebMvcProperties mvcProperties,
|
197 | 200 | ListableBeanFactory beanFactory, ObjectProvider<HttpMessageConverters> messageConvertersProvider,
|
198 | 201 | ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider,
|
199 |
| - ObjectProvider<DispatcherServletPath> dispatcherServletPath) { |
| 202 | + ObjectProvider<DispatcherServletPath> dispatcherServletPath, |
| 203 | + ObjectProvider<ServletRegistrationBean<?>> servletRegistrations) { |
200 | 204 | this.resourceProperties = resourceProperties;
|
201 | 205 | this.mvcProperties = mvcProperties;
|
202 | 206 | this.beanFactory = beanFactory;
|
203 | 207 | this.messageConvertersProvider = messageConvertersProvider;
|
204 | 208 | this.resourceHandlerRegistrationCustomizer = resourceHandlerRegistrationCustomizerProvider.getIfAvailable();
|
205 | 209 | this.dispatcherServletPath = dispatcherServletPath;
|
| 210 | + this.servletRegistrations = servletRegistrations; |
206 | 211 | this.mvcProperties.checkConfiguration();
|
207 | 212 | }
|
208 | 213 |
|
@@ -239,14 +244,19 @@ public void configurePathMatch(PathMatchConfigurer configurer) {
|
239 | 244 | this.mvcProperties.getPathmatch().isUseRegisteredSuffixPattern());
|
240 | 245 | this.dispatcherServletPath.ifAvailable((dispatcherPath) -> {
|
241 | 246 | String servletUrlMapping = dispatcherPath.getServletUrlMapping();
|
242 |
| - if (servletUrlMapping.equals("/")) { |
| 247 | + if (servletUrlMapping.equals("/") && singleDispatcherServlet()) { |
243 | 248 | UrlPathHelper urlPathHelper = new UrlPathHelper();
|
244 | 249 | urlPathHelper.setAlwaysUseFullPath(true);
|
245 | 250 | configurer.setUrlPathHelper(urlPathHelper);
|
246 | 251 | }
|
247 | 252 | });
|
248 | 253 | }
|
249 | 254 |
|
| 255 | + private boolean singleDispatcherServlet() { |
| 256 | + return this.servletRegistrations.stream().map(ServletRegistrationBean::getServlet) |
| 257 | + .filter(DispatcherServlet.class::isInstance).count() == 1; |
| 258 | + } |
| 259 | + |
250 | 260 | @Override
|
251 | 261 | @SuppressWarnings("deprecation")
|
252 | 262 | public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
0 commit comments