org.openide.util.lookup

## Annotation Type ServiceProvider

-     @Retention(value=SOURCE)
       @Target(value=TYPE)
      public @interface ServiceProvider

  Declarative registration of a singleton service provider. By marking an implementation class with this annotation, you automatically register that implementation, normally in `Lookup.getDefault()`. The class must be public and have a public no-argument constructor.

  Example of usage:

       package my.module;
       import org.netbeans.spi.whatever.Thing;
       import org.openide.util.lookup.ServiceProvider;
       @ServiceProvider(service=Thing.class)
       public class MyThing implements Thing {...}

  would result in a resource file `META-INF/services/org.netbeans.spi.whatever.Thing` containing the single line of text: `my.module.MyThing`

  Since:
    org.openide.util 7.20
  See Also:
    `Lookups.metaInfServices(ClassLoader)`

- - ### Required Element Summary

    Required Elements
    Modifier and Type | Required Element and Description
    --- | ---
    `Class<?>` | `service` The interface (or abstract class) to register this implementation under.

  - ### Optional Element Summary

    Optional Elements
    Modifier and Type | Optional Element and Description
    --- | ---
    `String` | `path` An optional path to register this implementation in.
    `int` | `position` An optional position in which to register this service relative to others.
    `String[]` | `supersedes` An optional list of implementations (given as fully-qualified class names) which this implementation supersedes.

- - ### Element Detail

    - #### service

          public abstract Class<?> service

      The interface (or abstract class) to register this implementation under. It is an error if the implementation class is not in fact assignable to the interface.

      If you need to register one class under multiple interfaces, use `ServiceProviders`.

      Requests to look up the specified interface should result in this implementation. Requests for any other types may or may not result in this implementation even if the implementation is assignable to those types.

  - - #### position

          public abstract int position

      An optional position in which to register this service relative to others. Lower-numbered services are returned in the lookup result first. Services with no specified position are returned last.
      Default:
        2147483647

  - - #### supersedes

          public abstract String[] supersedes

      An optional list of implementations (given as fully-qualified class names) which this implementation supersedes. If specified, those implementations will not be loaded even if they were registered. Useful on occasion to cancel a generic implementation and replace it with a more advanced one.

      Note: Dollar sign ($) is used in inner class names. For example `org.netbeans.modules.openfile.FileChooser$JavaFilesFilter`.

      Default:
        {}

  - - #### path

          public abstract String path

      An optional path to register this implementation in. For example, `Projects/sometype/Nodes` could be used. This style of registration would be recognized by `Lookups.forPath(java.lang.String)` rather than `Lookup.getDefault()`.

      The providers of a registration slot are advised to have a look at `NamedServiceDefinition` and consider using it since version 8.14. The `NamedServiceDefinition` offers various benefits over plain `path()` usage including type checking and lower possibility of typos.

      Default:
        ""

Copyright © 2025 API Design. All Rights Reserved.