Skip to content

Commit 819ca0d

Browse files
committed
Expose getters for the configured HandlerMapping's
Issue: SPR-15934
1 parent c9afdce commit 819ca0d

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,29 @@ public DispatcherHandler(ApplicationContext applicationContext) {
9191
}
9292

9393

94+
/**
95+
* Return all {@link HandlerMapping} beans detected by type in the
96+
* {@link #setApplicationContext injected context} and also
97+
* {@link AnnotationAwareOrderComparator#sort(List) sorted}.
98+
* @return immutable list with the configured mappings
99+
*/
100+
public List<HandlerMapping> getHandlerMappings() {
101+
return this.handlerMappings;
102+
}
103+
94104
@Override
95105
public void setApplicationContext(ApplicationContext applicationContext) {
96106
initStrategies(applicationContext);
97107
}
98108

109+
99110
protected void initStrategies(ApplicationContext context) {
100111
Map<String, HandlerMapping> mappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
101112
context, HandlerMapping.class, true, false);
102113

103-
this.handlerMappings = new ArrayList<>(mappingBeans.values());
114+
ArrayList<HandlerMapping> mappings = new ArrayList<>(mappingBeans.values());
104115
AnnotationAwareOrderComparator.sort(this.handlerMappings);
116+
this.handlerMappings = Collections.unmodifiableList(mappings);
105117

106118
Map<String, HandlerAdapter> adapterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
107119
context, HandlerAdapter.class, true, false);

spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,19 @@ private void initFlashMapManager(ApplicationContext context) {
770770
}
771771
}
772772

773+
/**
774+
* Return the configured {@link HandlerMapping} beans that were detected by
775+
* type in the {@link WebApplicationContext} or initialized based on the
776+
* default set of strategies from {@literal DispatcherServlet.properties}.
777+
* @return immutable list with the configured mappings or an empty list
778+
* @since 5.0
779+
*/
780+
public List<HandlerMapping> getHandlerMappings() {
781+
return this.handlerMappings != null ?
782+
Collections.unmodifiableList(this.handlerMappings) :
783+
Collections.emptyList();
784+
}
785+
773786
/**
774787
* Return this servlet's ThemeSource, if any; else return {@code null}.
775788
* <p>Default is to return the WebApplicationContext as ThemeSource,

0 commit comments

Comments
 (0)