Annotation Interface AutoService


@Documented @Target(TYPE) @Retention(RUNTIME) public @interface AutoService
An annotation which, when applied to a type, indicates that the type should automatically be registered as a service implementation into a service registry. The automatic registration happens based on service files which are automatically emitted from an annotation processor during the build process. Files that are located in the service directory inside a jar file will be automatically loaded and the given service implementation types will be resolved and registered. Each line of the file should contain one service implementation class binary name.
Since:
4.0
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    Get the name to use for the annotated service implementation.
    The service types that are implemented by the annotated service implementation.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    boolean
    Indicates if the annotated service type should be marked as the default service implementation after registration.
    boolean
    Indicates if the annotated service implementation should be registered as a singleton instance.
  • Element Details

    • services

      @NonNull @NonNull Class<?>[] services
      The service types that are implemented by the annotated service implementation. All types must be interfaces and assignable to the annotated type.
      Returns:
      the service types that are implemented by the annotated target type.
    • name

      Get the name to use for the annotated service implementation.
      Returns:
      the name to use for the annotated service implementation.
    • singleton

      boolean singleton
      Indicates if the annotated service implementation should be registered as a singleton instance. If that is the case, the instance of the class is resolved using dependency injection and registered into the registry. If this property is set to false the annotated implementation type will be constructed on each service instance retrieval using the public no-args constructor in the annotated class.
      Returns:
      true if the service should be registered as a singleton, false to retrieve a new instance each time.
      Default:
      true
    • markAsDefault

      boolean markAsDefault
      Indicates if the annotated service type should be marked as the default service implementation after registration.
      Returns:
      true if the service should be marked as the default after registration, false otherwise.
      Default:
      false