微服务的与测试
一、微服务项目整合
1、微服务项目结果预览
本项目通过一个名为microservice-mallmanagement的Maven父项目构建了四个子项目。关于这四个项目的描述如下:
microservice-eureka-server:用于服务注册发现
microservice-gateway-zuul:用于API网关
microservice-orderservice:用户订单管理服务
microservice-userservice:用于用户管理服务
2.项目功能介绍
(1)microservice-eureka-server(Eureka注册中心)
application.yml
(2)microservice-gateway-zuul(API网关)
application.yml
(3)microservice-orderservice(订单管理服务)
application.yml
(4)microservice-userservice(用户管理微服务)
application.yml
UserController类
3.微服务的启动和测试
microservice_mallmanagement.sql
表tb_user和tb_order
分别启动microservice-eureka-server、microservice-gateway-zuul、microservice-orderservice、microservice-userservice
http://localhost:8761/
启动成功后,即可对系统的功能进行测试,具体执行步骤如下:
(1)http://localhost:7900/order-service/order/findOrders/1
(2)http://localhost:8030/user/findOrders/shitou以上两种微服务的接口调用方法是通过调用各自的服务地址和对应的API接口方法进行的测试。
(2)测试API网关
http://localhost:8050/order-service/order/findOrders/1
http://localhost:8050/user-service/user/findOrders/shitou
二、接口可视化工具-Swagger-UI
1、Swagger-UI使用方法
(1)下载Swagger-UI项目
从GitHUB上拉取Swagger-UI项目代码
https://github.com/swagger-api/swagger-ui。git
(2)引入Swagger-UI
(3)在microservice-userservice的pm.xml中加入Swagger依赖
(4)编写配置类
2、Swagger-UI使用测试
(1)整合测试
http://localhost:8030/swagger-ui.html
(2)接口测试
http://localhost:7900/swagger-ui.html
3.小结
对微服务项目的使用有了进一步的认识,熟悉pring Boot和Spring Cloud相关组件的整合开发,同时还可以掌握接口测试工具Swagger-Ui的简单使用。