Java SPI is a standard java way to have binding between contracts and implementations. SPI used for several use cases such as Currency, Locale, TimeZone, DateFormat, Number, JDBC Driver, JPA, Json, JasonB, and many more. I believe the most classical example is for JDBC/JPA use cases where you have one common spec(contract) and multiple implementations for each database driver such as MySQL, Postgres, etc… SPI is interesting, shower I would not use SPI for common bread a butter SOA / Microservices use cases. Because often you just have one contract and one implementation, for that case using the new keyword or even basic DI/IoC I would say is much more desirable, easier, and much more simple and straightforward. However, if your use case has multiple implementations(beyond versioning) thats definitely something you should consider.
Originally published at http://diego-pacheco.blogspot.com on April 18, 2021.