The implementation of the generic interface is mainly used when there is no API interface and model class on the server side. All POJOs in the parameters and return values are represented by the Map and are usually used for framework integration. For example, to implement a universal remote service Mock framework, handle all service requests by implementing the GenericService interface.
In Java code, implement GenericService
interface:
package com.foo;
public class MyGenericService implements GenericService {
public Object $invoke(String methodName, String[] parameterTypes, Object[] args) throws GenericException {
if ("sayHello".equals(methodName)) {
return "Welcome " + args[0];
}
}
}
Declared in the Spring configuration file:
<bean id="genericService" class="com.foo.MyGenericService" />
<dubbo:service interface="com.foo.BarService" ref="genericService" />
...
// use org.apache.dubbo.rpc.service.GenericService can replace all implements
GenericService xxxService = new XxxGenericService();
// The instance is very heavy, which encapsulates all the registration center and service provider connection, please cache
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
// weak type service interface name
service.setInterface("com.xxx.XxxService");
service.setVersion("1.0.0");
// point to a generic serivce instance
service.setRef(xxxService);
// export service to registration center
service.export();
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.