一直以来想做一个综合性平台,平台X属于客户端,这个客户端可以让用户进行界面操作,如上传文件,并且提供接口,让用户进行一些必要的数据交互操作;平台Y属于监控平台,可以监控多少用户使用平台X。经过几天的摸索,发现使用springboot的spring-boot-admin-starter-server和spring-boot-admin-starter-client可以满足要求(也许有更好的脚手架,欢迎大家指正)
说在前面
1、编码工具:IntelliJ IDEA 2022.2.2
2、使用到的插件:
1、平台Y(统计用户,工程1)-spring-boot-admin-starter-server
一、先看效果
访问地址:电脑ip:8088
二、再看配置
只需要配置application.properties,重点就是设置下端口号
server.address=0.0.0.0
server.port=8088
2、平台X(用户端,工程2)-spring-boot-admin-starter-client
一、重点是配置application.properties
1、需要挂载到上面的服务器上面
spring.boot.admin.client.url=http://localhost:8088
spring.boot.admin.client.instance.name=${spring.application.name}
2、支持访问自定义首页
spring.mvc.view.prefix=classpath:/static/
spring.mvc.view.suffix=.html
3、定义访问的端口
server.address=0.0.0.0
server.port=9090
4、看完整配置
server.address=0.0.0.0
server.port=9090
# Spring Boot Admin client configuration
spring.boot.admin.client.url=http://localhost:8088
spring.boot.admin.client.instance.name=${spring.application.name}
spring.mvc.view.prefix=classpath:/static/
spring.mvc.view.suffix=.html
二、自定义首页
在static文件夹下创建一个index.html文件,运行之后,访问地址:电脑ip:9090/index.html,可以看到如下界面
三、请求接口
如上图中所示,点击按钮之后,可以获取接口数据,示例代码如下:
获取结果如下:
至此,初步的客户端和服务端的互通就完成了。