码迷,mamicode.com
首页 > 其他好文 > 详细

dubbo之泛化实现

时间:2017-09-17 22:16:38      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:class   dna   word   pack   parameter   api   rgs   客户端   通过   

实现泛化调用

泛化接口调用方式主要用于客户端没有 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];
        }
    }
}

dubbo之泛化实现

标签:class   dna   word   pack   parameter   api   rgs   客户端   通过   

原文地址:http://www.cnblogs.com/jmbkeyes/p/7537795.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!