搭建自己的服务器 使用(MOCO)

1>先安装java8的库,jdk8u181-x64.dmg

官网或者 https://www.cr173.com/mac/122803.html

惹是java库高于java8,就会出现类似错误

WARNING: An illegal reflective access operation has occurred

WARNING: Illegal reflective access by org.apache.ibatis.reflection.Reflector(file:/C:/Users/jiangcy/.m2/repository/org/mybatis/mybatis/3.4.5/mybatis-3.4.5.jar)to method java.lang.Object.finalize() 

WARNING: Please consider reporting this to the maintainers of org.apache.ibatis.reflection.Reflector

WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations

WARNING: All illegal access operations will be denied in a future release

2>

下载 moco-runner-0.10.2-standalone.jar

参考

https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/

我使用的是0.10.2,直接下载地址是

https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.10.2/moco-runner-0.10.2-standalone.jar

3>

在任意位置创建文件夹,我命名FilServiceApi,然后将下载的moco-runner-0.10.2-standalone.jar  放入FilServiceApi文件夹中

同时在当前文件夹新建json文件

使用终端新建单个命令: touch global.json

全部接口用单个文件配置的json

"request": { 

"method" : "get", 

"uri": "/getMethod" 

}, 

"response": { 

"text": "This is a Get Method!" 

}, 

"request": { 

"method" : "get", 

"uri": "/moveToRight" 

}, 

"response": { 

"text": "This is a moveToRight Method!" 

}, 

"request": { 

"uri": "/getMethodWithParams", 

"queries": { 

"param1": "1", 

"param2": "2" 

}, 

"response": { 

"text": "This is a moveToRight Method!" 

}, 

"request": { 

"method" : "post", 

"uri": "/postMethod", 

"headers" : { 

"content-type" : "application/json", 

"sessionid": "e566288ba77de98d" 

}, 

"forms" :{ 

"name" : "admin", 

"password" : "123456" 

}, 

"response": { 

"text": "This is a POST Method!" 

}, 

"response" : { 

"headers" : { 

"foo" : "bar" 

}, 

"include": "blah.json" 

单个文件配置(就是所有接口和返回数据全部在一个json文件里面)

java -jar moco-runner-0.10.2-standalone.jar start -p 1234 -c  global.json(端口自己自定义,不要有冲突) 

这个时候就已经启动了接口服务器

重点介绍多个单json文件配置

4>

同样可以在FilServiceApi文件下 终端新建josn文件:

touch  config.json

"include": "login/login_request.json" 

}, 

"include": "register/register_request.json" 

同时新建文件夹

login文件夹(登陆接口)


login_request.json

[ { "request": { 

"uri": "/test/login", 

"method": "get", 

"queries": { 

"username": "admin", 

"password": "123456" 

} }, 

"response": { 

"file": "login/login_response.json" 

} } ] 

login_response.json

"HttpStatus": 200, 

"HttpData": { 

"code": 200, 

"message": null, 

"data":[ 

"sta_n": 1, 

"equip_no": 5640, 

"set_no": 4, 

"set_nm": "向右运动", 

"set_type": "X", 

"main_instruction": "4", 

"minor_instruction": "-", 

"record": true, 

"action": "登陆设置", 

"value": null, 

"canexecution": true, 

"VoiceKeys": null, 

"EnableVoice": false, 

"Reserve1": null, 

"Reserve2": null, 

"Reserve3": null, 

"qr_equip_no": 0 

}, 

"HttpMessage": null 

register文件夹(注册接口)

register_request.json

"request": { 

"uri": "/test/register", 

"method": "get", 

"queries": { 

"username": "admin", 

"password": "123456" 

}, 

"response": { 

"file": "register/register_response.json" 

register_response.json

"HttpStatus": 200, 

"HttpData": { 

"code": 200, 

"message": null, 

"data":[ 

"sta_n": 1, 

"equip_no": 5640, 

"set_no": 4, 

"set_nm": "我是注册接口返回数据", 

"set_type": "X", 

"main_instruction": "4", 

"minor_instruction": "-", 

"record": true, 

"action": "注册", 

"value": null, 

"canexecution": true, 

"VoiceKeys": null, 

"EnableVoice": false, 

"Reserve1": null, 

"Reserve2": null, 

"Reserve3": null, 

"qr_equip_no": 0 

}, 

"HttpMessage": null 

全局文件配置(就是接口和返回数据分散在不同的json文件里面)

java -jar moco-runner-0.10.2-standalone.jar start -p 1235 -g  config.json 

这个时候查看接口是否正常

http://localhost:1235/test/login?username=admin&password=123456

http://localhost:1235/test/register?username=admin&password=123456

最后参考网址 

https://www.jianshu.com/p/0aa0ba7ded5d

https://www.jianshu.com/p/638da64422a0

https://blog.csdn.net/shensky711/article/details/52770686#如何在配置文件添加注释 

使用npm全局安装json-server

npm install -g json-server

可以通过查看版本号,来测试是否安装成功:

json-server -v

json-server --watch db.json

http://localhost:3000

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 英文文档,一开始我也是抗拒的,边翻译边看,也就花费了1个小时基本就阅读过了,我的英文基础其实很差。附上链接:链接:...
    lonecolonel阅读 10,020评论 3 1
  • 我是服务器小白。不了解真正的服务器是怎么搭建的。但是小编在本文将会讲述如何在十分钟内,在自己的电脑上搭建出服务器。...
    Airfei阅读 4,774评论 20 58
  • 首先环境的搭建,我是将zookeeper MongoDB redis 放在了203的服务器上,tomcat放在20...
    setsun阅读 1,867评论 0 1
  • Mockito简介什么是mock?在软件开发的世界之外, "mock"一词是指模仿或者效仿。 因此可以将“mock...
    燕京博士阅读 3,621评论 0 6
  • 风,经过的地方很吵。 叶子相撞有声音,翅膀颤抖有声音,尘埃漂浮再降落也有声音。 只有土壤,在城市迎来新生时,众人举...
    交叉歪阅读 262评论 0 0