diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java b/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java index c9b9f8b50d..6c759bd70e 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java @@ -91,17 +91,29 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware { } + /** + * Return all {@link HandlerMapping} beans detected by type in the + * {@link #setApplicationContext injected context} and also + * {@link AnnotationAwareOrderComparator#sort(List) sorted}. + * @return immutable list with the configured mappings + */ + public List getHandlerMappings() { + return this.handlerMappings; + } + @Override public void setApplicationContext(ApplicationContext applicationContext) { initStrategies(applicationContext); } + protected void initStrategies(ApplicationContext context) { Map mappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors( context, HandlerMapping.class, true, false); - this.handlerMappings = new ArrayList<>(mappingBeans.values()); + ArrayList mappings = new ArrayList<>(mappingBeans.values()); AnnotationAwareOrderComparator.sort(this.handlerMappings); + this.handlerMappings = Collections.unmodifiableList(mappings); Map adapterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors( context, HandlerAdapter.class, true, false); diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java index 46883cdbe2..3b3d151f2e 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java @@ -770,6 +770,19 @@ public class DispatcherServlet extends FrameworkServlet { } } + /** + * Return the configured {@link HandlerMapping} beans that were detected by + * type in the {@link WebApplicationContext} or initialized based on the + * default set of strategies from {@literal DispatcherServlet.properties}. + * @return immutable list with the configured mappings or an empty list + * @since 5.0 + */ + public List getHandlerMappings() { + return this.handlerMappings != null ? + Collections.unmodifiableList(this.handlerMappings) : + Collections.emptyList(); + } + /** * Return this servlet's ThemeSource, if any; else return {@code null}. *

Default is to return the WebApplicationContext as ThemeSource,