public interface Coherence {
public String naming();
}
public class DefaultCoherence implements Coherence {
public String naming() {
return "default coherence protocol";
}
}
public class Jobs implements Coherence {
public String naming() {
return "jobs coherence protocol";
}
}
classpath下META-INF\services\com.xxx.ddal.coherence.Coherence 写道
com.xxx.ddal.coherence.DefaultCoherence
com.xxx.ddal.coherence.Jobs
com.xxx.ddal.coherence.Jobs
@Test public void test() { ServiceLoader<Coherence> serviceLoader = ServiceLoader.load(Coherence.class); for (Coherence coherence : serviceLoader) { System.out.println(coherence.getClass()); System.out.println(coherence.naming()); } }
输出 写道
class com.xxx.ddal.coherence.DefaultCoherence
default coherence protocol
class com.xxx.ddal.coherence.Jobs
jobs coherence protocol
default coherence protocol
class com.xxx.ddal.coherence.Jobs
jobs coherence protocol
@Test
public void test() {
// String cn = "com.sun.xml.internal.ws.api.message.saaj.SAAJFactory";
String cn = "javax.print.PrintServiceLookup";
Class<?> clazz = null;
try {
clazz = Class.forName(cn);
} catch (ClassNotFoundException e) {
Assert.fail("Class not found: " + cn);
}
ServiceLoader<?> serviceLoader = ServiceLoader.load(clazz);
for (Object obj : serviceLoader) {
System.out.println(obj.getClass());
}
}
输出 写道
class sun.print.Win32PrintServiceLookup
public class ProviderService extends Provider {
static private final String DEFAULT_JAXWSPROVIDER =
"com.sun.xml.internal.ws.spi.ProviderImpl";
private Provider wrapper;
public ProviderService() {
Class<?> klass = null;
try {
klass = Class.forName(DEFAULT_JAXWSPROVIDER);
wrapper = (Provider) klass.newInstance();
} catch (Exception e) {
throw new WebServiceException("Provider " + DEFAULT_JAXWSPROVIDER + " error: " + e.getMessage(), e);
}
}
@Override
public ServiceDelegate createServiceDelegate(URL wsdlDocumentLocation, QName serviceName, Class serviceClass) {
return wrapper.createServiceDelegate(wsdlDocumentLocation, serviceName, serviceClass);
}
@Override
public Endpoint createEndpoint(String bindingId, Object implementor) {
return wrapper.createEndpoint(bindingId, implementor);
}
@Override
public Endpoint createAndPublishEndpoint(String address, Object implementor) {
return wrapper.createAndPublishEndpoint(address, implementor);
}
@Override
public EndpointReference readEndpointReference(Source eprInfoset) {
return wrapper.readEndpointReference(eprInfoset);
}
@Override
public <T> T getPort(EndpointReference endpointReference, Class<T> serviceEndpointInterface,
WebServiceFeature... features) {
return wrapper.getPort(endpointReference, serviceEndpointInterface, features);
}
@Override
public W3CEndpointReference createW3CEndpointReference(String address, QName serviceName, QName portName,
List<Element> metadata, String wsdlDocumentLocation, List<Element> referenceParameters) {
return wrapper.createW3CEndpointReference(address, serviceName, portName, metadata, wsdlDocumentLocation, referenceParameters);
}
}
META-INF\services\javax.xml.ws.spi.Provider 写道
com.javax.jws.distributed.ProviderService
Provider provider = Provider.provider(); // ProviderService