ServiceLoader is like an annotation Bean ans Autowired in the Spring. Kind of a plugin for a searching and loading service provider implementations.
public static <S> ServiceLoader<S> load(Class<S> sericeType)
SPI is a simplified form of IoC (Inversion of Control).
it could be this way :
module customer.abs.com{
requires PrintServiceAPI; // this module defines the service interface org.printing.Print
uses org.printing.Print; //specifies that this module uses this service
//observe that the module with implementation is not required.
}
package com.abc.customer;
public class ServiceLoader {
public static void main(String[] args) {
final ServiceLoader<Print> services = ServiceLoader.load(Print.class);
for (Print service : services) {
System.out.println("Name : " + service.name());
}
}
}
ServiceLoader is a class in the java.util package that provides a simple service-provider loading facility. It allows an application to specify one or more service interfaces and to discover and load implementations of those interfaces that are available in the runtime environment.
Option A is the correct way to use ServiceLoader to load a service provider with a Print interface. The load method of ServiceLoader takes a Class object representing the service interface and returns a new ServiceLoader instance that can be used to obtain instances of the service.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ASPushkin
9 months, 3 weeks agoASPushkin
5 months, 3 weeks agoStavok
1 year, 6 months agotmuralimanohar
1 year, 7 months ago