jsonrpc 介绍
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>
-
定义接口
@RestFul(api=Calculator.class,value="calculator")
public interface Calculator {
double add(double x, double y);
double multiply(double x, double y);
} -
实现接口
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;
}
} -
通过与 spring 集成,配置 servlet 。
<context-param>
contextConfigLocation
classpath:context.xml
org.springframework.web.context.ContextLoaderListener
dispatcher
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
1
rpc
com.quhaodian.servlet.RpcServlet
2
rpc
/rpc
-
客服端访问
String url="远程服务端servlet地址"
Calculator s = RestFulClient.getService(url, Calculator .class);
double result = calc.add(1.2, 7.5);
jsonrpc 官网
https://gitee.com/cng1985/jsonrpc
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。