Class ServiceLoaderUtil

java.lang.Object
org.operaton.commons.utils.ServiceLoaderUtil

public final class ServiceLoaderUtil extends Object
Utility class for loading services via ServiceLoader.
Since:
1.1
  • Method Details

    • loadSingleService

      public static <T> T loadSingleService(Class<T> serviceClass)
      Loads a single service implementation using ServiceLoader.

      This method first attempts to load the service using the thread context classloader. If no implementation is found, it tries again using the classloader of the service class itself.

      Type Parameters:
      T - the type of the service
      Parameters:
      serviceClass - the service class to load
      Returns:
      the first found implementation of the service
      Throws:
      IllegalStateException - if no implementation is found