@Test public void shouldNotFail() throws Exception { List<SomeService> loaded = ServiceLoaderUtils.load(classLoader, SomeService.class); assertNotNull(loaded); assertThat(loaded, hasSize(countOfServicesShouldBeLoaded)); }
public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) { List<T> foundServices = new ArrayList<>(); Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); while (checkHasNextSafely(iterator)) { try { T item = iterator.next(); foundServices.add(item); LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString())); } catch (ServiceConfigurationError e) { LOGGER.trace("Can't find services using Java SPI", e); LOGGER.error(e.getMessage()); } } return foundServices; }
ServiceLoaderUtils { public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) { List<T> foundServices = new ArrayList<>(); Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); while (checkHasNextSafely(iterator)) { try { T item = iterator.next(); foundServices.add(item); LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString())); } catch (ServiceConfigurationError e) { LOGGER.trace("Can't find services using Java SPI", e); LOGGER.error(e.getMessage()); } } return foundServices; } }
ServiceLoaderUtils { public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) { List<T> foundServices = new ArrayList<>(); Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); while (checkHasNextSafely(iterator)) { try { T item = iterator.next(); foundServices.add(item); LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString())); } catch (ServiceConfigurationError e) { LOGGER.trace("Can't find services using Java SPI", e); LOGGER.error(e.getMessage()); } } return foundServices; } ServiceLoaderUtils(); }
ServiceLoaderUtils { public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) { List<T> foundServices = new ArrayList<>(); Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); while (checkHasNextSafely(iterator)) { try { T item = iterator.next(); foundServices.add(item); LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString())); } catch (ServiceConfigurationError e) { LOGGER.trace("Can't find services using Java SPI", e); LOGGER.error(e.getMessage()); } } return foundServices; } ServiceLoaderUtils(); static List<T> load(ClassLoader classLoader, Class<T> serviceType); static boolean checkHasNextSafely(Iterator iterator); }
ServiceLoaderUtils { public static <T> List<T> load(ClassLoader classLoader, Class<T> serviceType) { List<T> foundServices = new ArrayList<>(); Iterator<T> iterator = ServiceLoader.load(serviceType, classLoader).iterator(); while (checkHasNextSafely(iterator)) { try { T item = iterator.next(); foundServices.add(item); LOGGER.debug(String.format("Found %s [%s]", serviceType.getSimpleName(), item.toString())); } catch (ServiceConfigurationError e) { LOGGER.trace("Can't find services using Java SPI", e); LOGGER.error(e.getMessage()); } } return foundServices; } ServiceLoaderUtils(); static List<T> load(ClassLoader classLoader, Class<T> serviceType); static boolean checkHasNextSafely(Iterator iterator);  }