Browse Source

Expose getters for the configured HandlerMapping's

Issue: SPR-15934
pull/1527/merge
Rossen Stoyanchev 7 years ago
parent
commit
819ca0dbd4
  1. 14
      spring-webflux/src/main/java/org/springframework/web/reactive/DispatcherHandler.java
  2. 13
      spring-webmvc/src/main/java/org/springframework/web/servlet/DispatcherServlet.java

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

@ -91,17 +91,29 @@ public class DispatcherHandler implements WebHandler, ApplicationContextAware { @@ -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<HandlerMapping> getHandlerMappings() {
return this.handlerMappings;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
initStrategies(applicationContext);
}
protected void initStrategies(ApplicationContext context) {
Map<String, HandlerMapping> mappingBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
context, HandlerMapping.class, true, false);
this.handlerMappings = new ArrayList<>(mappingBeans.values());
ArrayList<HandlerMapping> mappings = new ArrayList<>(mappingBeans.values());
AnnotationAwareOrderComparator.sort(this.handlerMappings);
this.handlerMappings = Collections.unmodifiableList(mappings);
Map<String, HandlerAdapter> adapterBeans = BeanFactoryUtils.beansOfTypeIncludingAncestors(
context, HandlerAdapter.class, true, false);

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

@ -770,6 +770,19 @@ public class DispatcherServlet extends FrameworkServlet { @@ -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<HandlerMapping> getHandlerMappings() {
return this.handlerMappings != null ?
Collections.unmodifiableList(this.handlerMappings) :
Collections.emptyList();
}
/**
* Return this servlet's ThemeSource, if any; else return {@code null}.
* <p>Default is to return the WebApplicationContext as ThemeSource,

Loading…
Cancel
Save