Expose getters for the configured HandlerMapping's
Issue: SPR-15934
This commit is contained in:
parent
c9afdce54b
commit
819ca0dbd4
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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…
Reference in New Issue