前言
最近公司的Springboot2.x项目中需要做一个服务监控工具,网上找到了springboot-admin。通过根据对 官方文档 和各位大佬的文章学习和分析,最终得以完成任务。
鉴于差点被网上各种文章绕晕,特此开篇写一个自认为靠谱的文章来介绍下springboot-admin的使用。
1、springboot-admin说来其实也简单(因为我是“刚需”来着)
总共分两步:
第一步:新建一个springboot的项目作为springboot-admin监控服务器(然后一堆配置等会儿唠);
第二步:在你需要被监控的服务中一顿配置(你的服务作为springboot-admin的被监控客户端服务);
2、springboot-admin服务器端
项目结构如下:
主要文件pom.xml、application.properties、ServerApplication.java
2.1、pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>SpringBoot2.x admin-server</name>
<description>服务监控</description>
<groupId>com.soybean.springboot</groupId>
<artifactId>admin-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 刚开始以为这个的版本号要跟springboot保持一致才行,但目前admin只有2.1.6,但是试了下是可以的 -->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<version>2.1.6</version>
</dependency>
<!--安全 -->
<de