Annotation Interface ReflectiveScan


@Retention(RUNTIME) @Target(TYPE) @Documented public @interface ReflectiveScan
Scan arbitrary types for use of Reflective. Typically used on @Configuration classes but can be added to any bean. Scanning happens during AOT processing, typically at build-time.

In the example below, com.example.app and its subpackages are scanned:


 @Configuration
 @ReflectiveScan("com.example.app")
 class MyConfiguration {
     // ...
 }

Either basePackageClasses() or basePackages() (or its alias value()) may be specified to define specific packages to scan. If specific packages are not defined, scanning will occur recursively beginning with the package of the class that declares this annotation.

A type does not need to be annotated at class level to be candidate, and this performs a "deep scan" by loading every class in the target packages and search for Reflective on types, constructors, methods, and fields. Enclosed classes are candidates as well. Classes that fail to load are ignored.

Since:
6.2
Author:
Stephane Nicoll
See Also:
  • Element Details

    • value

      @AliasFor("basePackages") String[] value
      Alias for basePackages().

      Allows for more concise annotation declarations if no other attributes are needed — for example, @ReflectiveScan("org.my.pkg") instead of @ReflectiveScan(basePackages = "org.my.pkg").

      Default:
      {}
    • basePackages

      @AliasFor("value") String[] basePackages
      Base packages to scan for reflective usage.

      value() is an alias for (and mutually exclusive with) this attribute.

      Use basePackageClasses() for a type-safe alternative to String-based package names.

      Default:
      {}
    • basePackageClasses

      Class<?>[] basePackageClasses
      Type-safe alternative to basePackages() for specifying the packages to scan for reflection usage. The package of each class specified will be scanned.

      Consider creating a special no-op marker class or interface in each package that serves no purpose other than being referenced by this attribute.

      Default:
      {}