private static List<Factory> discoverFactories(ClassLoader classLoader) {//spi机制加载类final Iterator<Factory> serviceLoaderIterator =ServiceLoader.load(Factory.class, classLoader).iterator();final List<Factory> loadResults = new ArrayList<>();while (true) {try {// error handling should also be applied to the hasNext() call because service// loading might cause problems here as wellif (!serviceLoaderIterator.hasNext()) {break;}loadResults.add(serviceLoaderIterator.next());} catch (Throwable t) {if (t instanceof NoClassDefFoundError) {LOG.debug("NoClassDefFoundError when loading a "+ Factory.class.getCanonicalName()+ ". This is expected when trying to load factory but no implementation is loaded.",t);} else {throw new RuntimeException("Unexpected error when trying to load service provider.", t);}}}return loadResults; }