Class HandlerTypePredicate

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

public final class HandlerTypePredicate extends Object implements Predicate<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 supertype.
  • Annotations -- for selecting handlers annotated in a specific way.

Composability methods on Predicate can be used :

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

    • test

      public boolean test(@Nullable Class<?> controllerType)
      Specified by:
      test in interface Predicate<Class<?>>
    • forAnyHandlerType

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

      public static HandlerTypePredicate forBasePackage(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(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(Class<?>... types)
      Match handlers that are assignable to a given type.
      Parameters:
      types - one or more handler supertypes
    • forAnnotation

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

      public static HandlerTypePredicate.Builder builder()
      Return a builder for a HandlerTypePredicate.