org.springframework.web.servlet.handler

Class AbstractHandlerMapping

    • Constructor Detail

      • AbstractHandlerMapping

        public AbstractHandlerMapping()
    • Method Detail

      • setDefaultHandler

        public void setDefaultHandler(@Nullable
                                      java.lang.Object defaultHandler)
        Set the default handler for this handler mapping. This handler will be returned if no specific mapping was found.

        Default is null, indicating no default handler.

      • getDefaultHandler

        @Nullable
        public java.lang.Object getDefaultHandler()
        Return the default handler for this handler mapping, or null if none.
      • setUrlPathHelper

        public void setUrlPathHelper(UrlPathHelper urlPathHelper)
        Set the UrlPathHelper to use for resolution of lookup paths.

        Use this to override the default UrlPathHelper with a custom subclass, or to share common UrlPathHelper settings across multiple HandlerMappings and MethodNameResolvers.

      • getUrlPathHelper

        public UrlPathHelper getUrlPathHelper()
        Return the UrlPathHelper implementation to use for resolution of lookup paths.
      • setPathMatcher

        public void setPathMatcher(PathMatcher pathMatcher)
        Set the PathMatcher implementation to use for matching URL paths against registered URL patterns. Default is AntPathMatcher.
        See Also:
        AntPathMatcher
      • getPathMatcher

        public PathMatcher getPathMatcher()
        Return the PathMatcher implementation to use for matching URL paths against registered URL patterns.
      • setInterceptors

        public void setInterceptors(java.lang.Object... interceptors)
        Set the interceptors to apply for all handlers mapped by this handler mapping.

        Supported interceptor types are HandlerInterceptor, WebRequestInterceptor, and MappedInterceptor. Mapped interceptors apply only to request URLs that match its path patterns. Mapped interceptor beans are also detected by type during initialization.

        Parameters:
        interceptors - array of handler interceptors
        See Also:
        adaptInterceptor(java.lang.Object), HandlerInterceptor, WebRequestInterceptor
      • setCorsConfigurations

        public void setCorsConfigurations(java.util.Map<java.lang.String,CorsConfiguration> corsConfigurations)
        Set the "global" CORS configurations based on URL patterns. By default the first matching URL pattern is combined with the CORS configuration for the handler, if any.
        Since:
        4.2
        See Also:
        setCorsConfigurationSource(CorsConfigurationSource)
      • setCorsConfigurationSource

        public void setCorsConfigurationSource(CorsConfigurationSource corsConfigurationSource)
        Set the "global" CORS configuration source. By default the first matching URL pattern is combined with the CORS configuration for the handler, if any.
        Since:
        5.1
        See Also:
        setCorsConfigurations(Map)
      • setOrder

        public void setOrder(int order)
        Specify the order value for this HandlerMapping bean.

        The default value is Ordered.LOWEST_PRECEDENCE, meaning non-ordered.

        See Also:
        Ordered.getOrder()
      • getOrder

        public int getOrder()
        Description copied from interface: Ordered
        Get the order value of this object.

        Higher values are interpreted as lower priority. As a consequence, the object with the lowest value has the highest priority (somewhat analogous to Servlet load-on-startup values).

        Same order values will result in arbitrary sort positions for the affected objects.

        Specified by:
        getOrder in interface Ordered
        Returns:
        the order value
        See Also:
        Ordered.HIGHEST_PRECEDENCE, Ordered.LOWEST_PRECEDENCE
      • setBeanName

        public void setBeanName(java.lang.String name)
        Description copied from interface: BeanNameAware
        Set the name of the bean in the bean factory that created this bean.

        Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

        Specified by:
        setBeanName in interface BeanNameAware
        Parameters:
        name - the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils.originalBeanName(String) method to extract the original bean name (without suffix), if desired.
      • formatMappingName

        protected java.lang.String formatMappingName()
      • extendInterceptors

        protected void extendInterceptors(java.util.List<java.lang.Object> interceptors)
        Extension hook that subclasses can override to register additional interceptors, given the configured interceptors (see setInterceptors(java.lang.Object...)).

        Will be invoked before initInterceptors() adapts the specified interceptors into HandlerInterceptor instances.

        The default implementation is empty.

        Parameters:
        interceptors - the configured interceptor List (never null), allowing to add further interceptors before as well as after the existing interceptors
      • getHandlerInternal

        @Nullable
        protected abstract java.lang.Object getHandlerInternal(HttpServletRequest request)
                                                                  throws java.lang.Exception
        Look up a handler for the given request, returning null if no specific one is found. This method is called by getHandler(javax.servlet.http.HttpServletRequest); a null return value will lead to the default handler, if one is set.

        On CORS pre-flight requests this method should return a match not for the pre-flight request but for the expected actual request based on the URL path, the HTTP methods from the "Access-Control-Request-Method" header, and the headers from the "Access-Control-Request-Headers" header thus allowing the CORS configuration to be obtained via getCorsConfiguration(Object, HttpServletRequest),

        Note: This method may also return a pre-built HandlerExecutionChain, combining a handler object with dynamically determined interceptors. Statically specified interceptors will get merged into such an existing chain.

        Parameters:
        request - current HTTP request
        Returns:
        the corresponding handler instance, or null if none found
        Throws:
        java.lang.Exception - if there is an internal error
      • getCorsConfiguration

        @Nullable
        protected CorsConfiguration getCorsConfiguration(java.lang.Object handler,
                                                                   HttpServletRequest request)
        Retrieve the CORS configuration for the given handler.
        Parameters:
        handler - the handler to check (never null).
        request - the current request.
        Returns:
        the CORS configuration for the handler, or null if none
        Since:
        4.2