类 AbstractUrlHandlerMapping

  • 所有已实现的接口:
    Aware, BeanNameAware, ApplicationContextAware, Ordered, HandlerMapping
    直接已知子类:
    SimpleUrlHandlerMapping

    public abstract class AbstractUrlHandlerMapping
    extends AbstractHandlerMapping
    Abstract base class for URL-mapped HandlerMapping implementations.

    Supports direct matches, e.g. a registered "/test" matches "/test", and various path pattern matches, e.g. a registered "/t*" pattern matches both "/test" and "/team", "/test/*" matches all paths under "/test", "/test/**" matches all paths below "/test". For details, see the PathPattern javadoc.

    Will search all path patterns to find the most specific match for the current request path. The most specific pattern is defined as the longest path pattern with the fewest captured variables and wildcards.

    从以下版本开始:
    5.0
    作者:
    Rossen Stoyanchev, Juergen Hoeller, Brian Clozel
    • 方法详细资料

      • setLazyInitHandlers

        public void setLazyInitHandlers​(boolean lazyInitHandlers)
        Set whether to lazily initialize handlers. Only applicable to singleton handlers, as prototypes are always lazily initialized. Default is "false", as eager initialization allows for more efficiency through referencing the controller objects directly.

        If you want to allow your controllers to be lazily initialized, make them "lazy-init" and set this flag to true. Just making them "lazy-init" will not work, as they are initialized through the references from the handler mapping in this case.

      • getHandlerMap

        public final Map<PathPattern,​ObjectgetHandlerMap()
        Return a read-only view of registered path patterns and handlers which may may be an actual handler instance or the bean name of lazily initialized handler.
      • lookupHandler

        @Nullable
        protected Object lookupHandler​(PathContainer lookupPath,
                                       ServerWebExchange exchange)
                                throws Exception
        Look up a handler instance for the given URL lookup path.

        Supports direct matches, e.g. a registered "/test" matches "/test", and various path pattern matches, e.g. a registered "/t*" matches both "/test" and "/team". For details, see the PathPattern class.

        参数:
        lookupPath - the URL the handler is mapped to
        exchange - the current exchange
        返回:
        the associated handler instance, or null if not found
        抛出:
        Exception
        另请参阅:
        PathPattern
      • validateHandler

        protected void validateHandler​(Object handler,
                                       ServerWebExchange exchange)
        Validate the given handler against the current request.

        The default implementation is empty. Can be overridden in subclasses, for example to enforce specific preconditions expressed in URL mappings.

        参数:
        handler - the handler object to validate
        exchange - current exchange
      • registerHandler

        protected void registerHandler​(String urlPath,
                                       Object handler)
                                throws BeansException,
                                       IllegalStateException
        Register the specified handler for the given URL path.
        参数:
        urlPath - the URL the bean should be mapped to
        handler - the handler instance or handler bean name String (a bean name will automatically be resolved into the corresponding handler bean)
        抛出:
        BeansException - if the handler couldn't be registered
        IllegalStateException - if there is a conflicting handler registered