W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
實現(xiàn)一個通用的遠程服務(wù) Mock 框架,可通過實現(xiàn) GenericService 接口處理所有服務(wù)請求
泛接口實現(xiàn)方式主要用于服務(wù)器端沒有 API 接口及模型類元的情況,參數(shù)及返回值中的所有 POJO 均用 Map 表示,通常用于框架集成,比如:實現(xiàn)一個通用的遠程服務(wù) Mock 框架,可通過實現(xiàn) GenericService 接口處理所有服務(wù)請求。
在 Java 代碼中實現(xiàn) ?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];
}
}
}
在 Spring 配置申明服務(wù)的實現(xiàn):
<bean id="genericService" class="com.foo.MyGenericService" />
<dubbo:service interface="com.foo.BarService" ref="genericService" />
...
// 用org.apache.dubbo.rpc.service.GenericService可以替代所有接口實現(xiàn)
GenericService xxxService = new XxxGenericService();
// 該實例很重量,里面封裝了所有與注冊中心及服務(wù)提供方連接,請緩存
ServiceConfig<GenericService> service = new ServiceConfig<GenericService>();
// 弱類型接口名
service.setInterface("com.xxx.XxxService");
service.setVersion("1.0.0");
// 指向一個通用服務(wù)實現(xiàn)
service.setRef(xxxService);
// 暴露及注冊服務(wù)
service.export();
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: