搭建自己的服務(wù)器 使用(MOCO)

1>先安裝java8的庫,jdk8u181-x64.dmg

官網(wǎng)或者 https://www.cr173.com/mac/122803.html

惹是java庫高于java8,就會(huì)出現(xiàn)類似錯(cuò)誤

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>

在任意位置創(chuàng)建文件夾,我命名FilServiceApi,然后將下載的moco-runner-0.10.2-standalone.jar ?放入FilServiceApi文件夾中

同時(shí)在當(dāng)前文件夾新建json文件

使用終端新建單個(gè)命令: touch global.json

全部接口用單個(gè)文件配置的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"?

}?

]?

單個(gè)文件配置(就是所有接口和返回?cái)?shù)據(jù)全部在一個(gè)json文件里面)

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

這個(gè)時(shí)候就已經(jīng)啟動(dòng)了接口服務(wù)器

重點(diǎn)介紹多個(gè)單json文件配置

4>

同樣可以在FilServiceApi文件下 終端新建josn文件:

touch ?config.json

[?

{?

"include": "login/login_request.json"?

},?

{?

"include": "register/register_request.json"?

}?

]?

同時(shí)新建文件夾

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": "向右運(yùn)動(dòng)",?

"set_type": "X",?

"main_instruction": "4",?

"minor_instruction": "-",?

"record": true,?

"action": "登陸設(shè)置",?

"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": "我是注冊接口返回?cái)?shù)據(jù)",?

"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?

}?

全局文件配置(就是接口和返回?cái)?shù)據(jù)分散在不同的json文件里面)

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

這個(gè)時(shí)候查看接口是否正常

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

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

最后參考網(wǎng)址?

http://www.itdecent.cn/p/0aa0ba7ded5d

http://www.itdecent.cn/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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 英文文檔,一開始我也是抗拒的,邊翻譯邊看,也就花費(fèi)了1個(gè)小時(shí)基本就閱讀過了,我的英文基礎(chǔ)其實(shí)很差。附上鏈接:鏈接:...
    lonecolonel閱讀 10,402評論 3 1
  • 我是服務(wù)器小白。不了解真正的服務(wù)器是怎么搭建的。但是小編在本文將會(huì)講述如何在十分鐘內(nèi),在自己的電腦上搭建出服務(wù)器。...
    Airfei閱讀 4,979評論 20 58
  • 首先環(huán)境的搭建,我是將zookeeper MongoDB redis 放在了203的服務(wù)器上,tomcat放在20...
    setsun閱讀 2,058評論 0 1
  • Mockito簡介什么是mock?在軟件開發(fā)的世界之外, "mock"一詞是指模仿或者效仿。 因此可以將“mock...
    燕京博士閱讀 3,780評論 0 6
  • 風(fēng),經(jīng)過的地方很吵。 葉子相撞有聲音,翅膀顫抖有聲音,塵埃漂浮再降落也有聲音。 只有土壤,在城市迎來新生時(shí),眾人舉...
    交叉歪閱讀 289評論 0 0

友情鏈接更多精彩內(nèi)容