Understanding the SPI Mechanism in Java
The SPI (Service Provider Interface) is a built-in service provider discovery mechanism in JDK.It can find service implementations for a specific interface.Demo: public class TestSpi { public static void main(String[] args) throws InstantiationException, IllegalAccessException { ServiceLoader<SpiInterface> load = ServiceLoader.load(SpiInterface.class); Iterator<SpiInterface> iterator = load.iterator(); if (iterator.hasNext()) { SpiInterface next = iterator.next(); next.spiInterFaceMethod("hello"); } } } Interface: … Read more