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 7f08043ecad..9c56dba232b 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,20 +770,6 @@ 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}. - *

Note: This method may return {@code null} if invoked - * prior to {@link #onRefresh(ApplicationContext)}. - * @return immutable list with the configured mappings or {@code null} - * @since 5.0 - */ - @Nullable - public List getHandlerMappings() { - return this.handlerMappings != null ? Collections.unmodifiableList(this.handlerMappings) : null; - } - /** * Return this servlet's ThemeSource, if any; else return {@code null}. *

Default is to return the WebApplicationContext as ThemeSource, @@ -793,12 +779,7 @@ public class DispatcherServlet extends FrameworkServlet { */ @Nullable public final ThemeSource getThemeSource() { - if (getWebApplicationContext() instanceof ThemeSource) { - return (ThemeSource) getWebApplicationContext(); - } - else { - return null; - } + return (getWebApplicationContext() instanceof ThemeSource ? (ThemeSource) getWebApplicationContext() : null); } /** @@ -811,6 +792,21 @@ public class DispatcherServlet extends FrameworkServlet { return this.multipartResolver; } + /** + * 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}. + *

Note: This method may return {@code null} if invoked + * prior to {@link #onRefresh(ApplicationContext)}. + * @return an immutable list with the configured mappings, or {@code null} + * if not initialized yet + * @since 5.0 + */ + @Nullable + public final List getHandlerMappings() { + return (this.handlerMappings != null ? Collections.unmodifiableList(this.handlerMappings) : null); + } + /** * Return the default strategy object for the given strategy interface. *

The default implementation delegates to {@link #getDefaultStrategies},