org.springframework.web.method

Class HandlerTypePredicate

  • java.lang.Object
    • org.springframework.web.method.HandlerTypePredicate
  • All Implemented Interfaces:
    java.util.function.Predicate<java.lang.Class<?>>


    public final class HandlerTypePredicate
    extends java.lang.Object
    implements java.util.function.Predicate<java.lang.Class<?>>
    A Predicate to match request handling component types if any of the following selectors match:
    • Base packages -- for selecting handlers by their package.
    • Assignable types -- for selecting handlers by super type.
    • Annotations -- for selecting handlers annotated in a specific way.

    Composability methods on Predicate can be used :

     Predicate<Class<?>> predicate =
                    HandlerTypePredicate.forAnnotation(RestController)
                                    .and(HandlerTypePredicate.forBasePackage("org.example"));
     
    Since:
    5.1
    Author:
    Rossen Stoyanchev
    • Method Detail

      • test

        public boolean test(java.lang.Class<?> controllerType)
        Specified by:
        test in interface java.util.function.Predicate<java.lang.Class<?>>
      • forAnyHandlerType

        public static HandlerTypePredicate forAnyHandlerType()
        Predicate that applies to any handlers.
      • forBasePackage

        public static HandlerTypePredicate forBasePackage(java.lang.String... packages)
        Match handlers declared under a base package, e.g. "org.example".
        Parameters:
        packages - one or more base package names
      • forBasePackageClass

        public static HandlerTypePredicate forBasePackageClass(java.lang.Class<?>... packageClasses)
        Type-safe alternative to forBasePackage(String...) to specify a base package through a class.
        Parameters:
        packageClasses - one or more base package classes
      • forAssignableType

        public static HandlerTypePredicate forAssignableType(java.lang.Class<?>... types)
        Match handlers that are assignable to a given type.
        Parameters:
        types - one or more handler super types
      • forAnnotation

        @SafeVarargs
        public static HandlerTypePredicate forAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation>... annotations)
        Match handlers annotated with a specific annotation.
        Parameters:
        annotations - one or more annotations to check for