<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          jsonrpc一個(gè)簡(jiǎn)單的 Java RPC 組件

          聯(lián)合創(chuàng)作 · 2023-09-23 12:28

          jsonrpc 是一個(gè)簡(jiǎn)單的 java rpc 組件, 部分代碼參考:https://github.com/RitwikSaikia/jsonrpc 這部分代碼版權(quán)歸 RitwikSaikia 所有。服務(wù)端緩存、客服端緩存、注解支持,spring 支持等版權(quán)歸 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. 實(shí)現(xiàn)接口

             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. 通過(guò)與 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. 客服端訪問(wèn)

                String url="遠(yuǎn)程服務(wù)端servlet地址"
            
                Calculator  s = RestFulClient.getService(url, Calculator .class);
            
                double result = calc.add(1.2, 7.5);
          瀏覽 19
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  欧美日本一频道 | 第四色成人网站 | 成人免费观看视频亚洲 | 日本手机黄色视频 | 91成人免费在线 |