Generic Service

Generic service in dubbo

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:

public class MyGenericService implements GenericService {

    public Object $invoke(String methodName, String[] parameterTypes, Object[] args) throws GenericException {
        if ("sayHello".equals(methodName)) {
            return "Welcome " + args[0];

Export generic implements via Spring

Declared in the Spring configuration file:

<bean id="genericService" class="" />
<dubbo:service interface="" ref="genericService" />

Export generic implements via API

// 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
// point to a generic serivce instance

// export service to registration center

Last modified December 22, 2020: clean up website (6e41905afab)