diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index f19737c996..290dd106ee 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -277,6 +277,34 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport this.interceptors.addAll(Arrays.asList(interceptors)); } + /** + * Return all configured interceptors adapted to {@link HandlerInterceptor}. + * @return the array of configured interceptors, or {@code null} if none + * are configured; this method also returns {@code null} also if called too + * early, or more specifically before. + * {@link org.springframework.context.ApplicationContextAware#setApplicationContext}. + */ + @Nullable + public final HandlerInterceptor[] getAdaptedInterceptors() { + return (!this.adaptedInterceptors.isEmpty() ? + this.adaptedInterceptors.toArray(new HandlerInterceptor[0]) : null); + } + + /** + * Return all configured {@link MappedInterceptor}s as an array. + * @return the array of {@link MappedInterceptor}s, or {@code null} if none + */ + @Nullable + protected final MappedInterceptor[] getMappedInterceptors() { + List mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size()); + for (HandlerInterceptor interceptor : this.adaptedInterceptors) { + if (interceptor instanceof MappedInterceptor mappedInterceptor) { + mappedInterceptors.add(mappedInterceptor); + } + } + return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null); + } + /** * Set "global" CORS configuration mappings. The first matching URL pattern * determines the {@code CorsConfiguration} to use which is then further @@ -455,33 +483,6 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport } } - /** - * Return the adapted interceptors as {@link HandlerInterceptor} array. - * @return the array of {@link HandlerInterceptor HandlerInterceptor}s, - * or {@code null} if none - */ - @Nullable - protected final HandlerInterceptor[] getAdaptedInterceptors() { - return (!this.adaptedInterceptors.isEmpty() ? - this.adaptedInterceptors.toArray(new HandlerInterceptor[0]) : null); - } - - /** - * Return all configured {@link MappedInterceptor}s as an array. - * @return the array of {@link MappedInterceptor}s, or {@code null} if none - */ - @Nullable - protected final MappedInterceptor[] getMappedInterceptors() { - List mappedInterceptors = new ArrayList<>(this.adaptedInterceptors.size()); - for (HandlerInterceptor interceptor : this.adaptedInterceptors) { - if (interceptor instanceof MappedInterceptor mappedInterceptor) { - mappedInterceptors.add(mappedInterceptor); - } - } - return (!mappedInterceptors.isEmpty() ? mappedInterceptors.toArray(new MappedInterceptor[0]) : null); - } - - /** * Return "true" if this {@code HandlerMapping} has been * {@link #setPatternParser enabled} to use parsed {@code PathPattern}s.