SPI 加載配置文件,一種很常見,但以前我卻不知道的方式
目錄
1.SPI使用JDK自帶方法:ServiceLoader
public class SpiTest {
@Test
public void test() {
//JDK自帶,就是配置文件的加載
ServiceLoader<SpiService> loader = ServiceLoader.load(SpiService.class);
loader.forEach(load ->{
load.find();
});
}
}
2.關鍵點是:load 接口,接口需要配置到 指定目錄
並且配置的路徑和接口包名地址需要一致
配置文件內容:也需要對應
3.執行結果