public static < T > T loadUniqueServiceProvider ( Class < T > klass ) { List < T > providers = findServiceProviders ( klass ) ; if ( providers . isEmpty ( ) ) { throw new NoServiceProviderException ( klass . getName ( ) + ": no service provider found in META-INF/services on classpath" ) ; } else if ( providers . size ( ) > 1 ) { throw new NonUniqueServiceProviderException ( klass . getName ( ) + ": multiple service providers found in META-INF/services on classpath" ) ; } return providers . get ( 0 ) ; }
Returns the unique service provider for a given service and throws an exception if there is no unique provider