dubbo泛化实现

清疚 2022-03-21 16:47 228阅读 0赞

转自:https://www.cnblogs.com/jmbkeyes/p/7537795.html

实现泛化调用

泛化接口调用方式主要用于客户端没有 API 接口及模型类元的情况,参数及返回值中的所有 POJO 均用 Map 表示,通常用于框架集成,比如:实现一个通用的服务测试框架,可通过 GenericService 调用所有服务实现。

通过 Spring 实现泛化调用

在 Spring 配置申明服务的实现:

  1. <bean id="genericService" class="com.foo.MyGenericService" />
  2. <dubbo:service interface="com.foo.BarService" ref="genericService" />

在 Java 代码中实现 GenericService 接口:

  1. package com.foo;
  2. public class MyGenericService implements GenericService {
  3. public Object $invoke(String methodName, String[] parameterTypes, Object[] args) throws GenericException {
  4. if ("sayHello".equals(methodName)) {
  5. return "Welcome " + args[0];
  6. }
  7. }
  8. }

发表评论

表情:
评论列表 (有 0 条评论,228人围观)

还没有评论,来说两句吧...

相关阅读

    相关 dubbo调用

    dubbo泛化调用 一、前言 > 泛接口调用方式主要用于客户端没有API接口及模型类元的情况,参数及返回值中的所有POJO均用Map表示,通常用于框架集成,比如:实