實現泛化調用
泛化接口調用方式主要用於客戶端沒有 API 接口及模型類元的情況,參數及返回值中的所有 POJO 均用 Map
表示,通常用於框架集成,比如:實現一個通用的服務測試框架,可通過 GenericService
調用所有服務實現。
通過 Spring 實現泛化調用
在 Spring 配置申明服務的實現:
<bean id="genericService" class="com.foo.MyGenericService" /> <dubbo:service interface="com.foo.BarService" ref="genericService" />
在 Java 代碼中實現 GenericService
接口:
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]; } } }