Java Service Provider Interface (SPI)

compared with
Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (5)

View page history
h3. Create a provider
As provider we mean an implementation of a contract. See example below:
{code}
public class MyProvider implements MyContract
{code}
To publish this provider through the SPI we have found a very useful project [https://metainf-services.dev.java.net/] that allow us to write the SPI infos simply using the annotation *@MetaInfServices*. See example below
{code}
@MetaInfServices
{code}
to use this project from maven you have to put the following dependency in your pom

{code:xml|title=pom fragment}
{code}
Note: *optional* means that this dependency will be not include in project that refer to your provider project. Run *clean* & *install* (or *package*) and automatically the SPI information will be included in your jar

h3. Create a Factory
Finally we can develop the factory that discover provider and instantiate it
{code:java}