一、搭建server端
1. 创建SpringBoot项目;
2.启动类加:@EnableAdminServer;
package com.example.admindemo;
import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@EnableAdminServer
@SpringBootApplication
public class AdmindemoApplication {
public static void main(String[] args) {
SpringApplication.run(AdmindemoApplication.class, args);
}
}
3.配置application.properties
spring.application.name=admin-service
server.port=8989
4. 依赖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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>admindemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>admindemo</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<admin.version>2.3.0</admin.version>
</properties>
<dependencies>
<!-- spring-boot-admin 服务端-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-server</artifactId>
<exclusions>
<exclusion>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
</exclusion>
</exclusions>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.10.RELEASE</version>
</dependency>
<!-- spring-boot-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4.浏览器访问:http://localhost:8989
二、搭建client端
1.添加依赖 pom.xml
<!--添加actuator依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!--spring boot admin依赖-->
<dependency>
<groupId>de.codecentric</groupId>
<artifactId>spring-boot-admin-starter-client</artifactId>
<version>2.3.1</version>
</dependency>
注意对应版本:
spring-boot-starter-parent 版本:2.1.3.RELEASE
spring-cloud-dependencies 版本:Greenwich.SR2
2. 加配置 bootstrap.yml
spring:
boot:
admin:
client:
url: http://localhost:8989
management:
endpoints:
web:
exposure:
include: "*"