jsonrpc 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
jsonrpc 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
jsonrpc 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 Apache
开发语言 Java
操作系统 跨平台
软件类型 开源软件
开源组织
地区 国产
投 递 者 ada_young
适用人群 未知
收录时间 2018-04-11

软件简介

jsonrpc 是一个简单的 java rpc 组件, 部分代码参考:https://github.com/RitwikSaikia/jsonrpc 这部分代码版权归 RitwikSaikia 所有。服务端缓存、客服端缓存、注解支持,spring 支持等版权归 ada.young 所有。

maven使用

       <dependency>
           <groupId>com.quhaodian.jsonrpc</groupId>
           <artifactId>core</artifactId>
           <version>1.01</version>
       </dependency>

使用方法

  1. 定义接口

         @RestFul(api=Calculator.class,value="calculator")
         public interface Calculator {
             double add(double x, double y);
             double multiply(double x, double y);
         }
  2. 实现接口

     public class SimpleCalculatorImpl implements Calculator {
     
         public double add(double x, double y) {
           return x + y;
         }
         
         public double multiply(double x, double y) {
           return x * y;
         }
     
     }
  3. 通过与 spring 集成,配置 servlet 。

     <context-param>
         <param-name>contextConfigLocation</param-name>
         <param-value>classpath:context.xml</param-value>
     </context-param>
     
     <listener>
         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener>
     
     <servlet>
         <servlet-name>dispatcher</servlet-name>
         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
         <init-param>
             <param-name>contextConfigLocation</param-name>
             <param-value></param-value>
         </init-param>
         <load-on-startup>1</load-on-startup>
     </servlet> 
       
     <servlet>
         <servlet-name>rpc</servlet-name>
         <servlet-class>com.quhaodian.servlet.RpcServlet</servlet-class>
         <load-on-startup>2</load-on-startup>
     </servlet>
     
     <servlet-mapping>
          <servlet-name>rpc</servlet-name>
          <url-pattern>/rpc</url-pattern>
     </servlet-mapping>
  4. 客服端访问

        String url="远程服务端servlet地址"
    
        Calculator  s = RestFulClient.getService(url, Calculator .class);
    
        double result = calc.add(1.2, 7.5);
展开阅读全文

代码

的 Gitee 指数为
超过 的项目

评论

点击引领话题📣
暂无内容
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
0 评论
9 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部