Spring Boot - Admin服务器

Spring Boot - Admin服务器 首页 / Spring Boot入门教程 / Spring Boot - Admin服务器

使用Spring Boot Actuator端点监视您的应用程序有点困难。因为,如果您有" n"个应用程序,则每个应用程序都具有单独的执行器端点,从而使监视变得困难。 Spring Boot Admin Server是一个用于管理和监视您的微服务应用程序的应用程序。

为了处理这种情况,CodeCentric团队提供了一个Spring Boot Admin UI,可在一处管理和监视所有Spring Boot应用程序Actuator端点。

链接:https://www.learnfk.comhttps://www.learnfk.com/spring-boot/spring-boot-admin-server.html

来源:LearnFk无涯教程网

为了构建Spring Boot Admin Server,无涯教程需要在构建配置文件中添加以下依赖项。

Maven用户可以在pom.xml文件中添加以下依赖项-

<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-server</artifactId>
   <version>1.5.5</version>
</dependency>
<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-server-ui</artifactId>
   <version>1.5.5</version>
</dependency>

Gradle用户可以在build.gradle文件中添加以下依赖项-

compile group: 'de.codecentric', name: 'spring-boot-admin-server', version: '1.5.5'
compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: '1.5.5'

在主Spring Boot应用程序类文件中添加@EnableAdminServer批注。 @EnableAdminServer批注用于使您成为Admin Server来监视所有其他微服务。

package com.learnfk.adminserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import de.codecentric.boot.admin.config.EnableAdminServer;

@SpringBootApplication
@EnableAdminServer
public class AdminserverApplication {   
   public static void main(String[] args) {
      SpringApplication.run(AdminserverApplication.class, args);
   }
}

现在,在application.properties文件中定义server.port和应用程序名称,如下所示:

server.port=9090
spring.application.name=adminserver

对于YAML用户,使用以下属性在application.yml文件中定义端口号和应用程序名称。

server:
   port: 9090
spring:
   application:
      name: adminserver

生成配置文件如下。

对于Maven用户– 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>
   <groupId>com.learnfk</groupId>
   <artifactId>adminserver</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>adminserver</name>
   <description>Demo project for Spring Boot</description>

   <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.5.9.RELEASE</version>
      <relativePath /> <!-- lookup parent from repository -->
   </parent>

   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
      <java.version>1.8</java.version>
   </properties>

   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
      </dependency>

      <dependency>
         <groupId>de.codecentric</groupId>
         <artifactId>spring-boot-admin-server</artifactId>
         <version>1.5.5</version>
      </dependency>
      
      <dependency>
         <groupId>de.codecentric</groupId>
         <artifactId>spring-boot-admin-server-ui</artifactId>
         <version>1.5.5</version>
      </dependency>

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter-test</artifactId>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>
   
</project>

对于Gradle用户– build.gradle文件

buildscript {
   ext {
      springBootVersion='1.5.9.RELEASE'
   }
   repositories {
      mavenCentral()
   }
   dependencies {
      classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
   }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'

group='com.learnfk'
version='0.0.1-SNAPSHOT'
sourceCompatibility=1.8
repositories {   
   mavenCentral()
}
dependencies {
   compile('org.springframework.boot:spring-boot-starter')
   compile group: 'de.codecentric', name: 'spring-boot-admin-server', version: '1.5.5'
   compile group: 'de.codecentric', name: 'spring-boot-admin-server-ui', version: '1.5.5'   
   testCompile('org.springframework.boot:spring-boot-starter-test')
}

您可以创建一个可执行的JAR文件,并使用以下Maven或Gradle命令运行Spring Boot应用程序-

对于Maven,请使用此处显示的命令-

mvn clean install

在" BUILD SUCCESS"之后,您可以在目标目录下找到JAR文件。

对于Gradle,请使用此处显示的命令-

gradle clean build

在" BUILD SUCCESSFUL"之后,您可以在build/libs目录下找到JAR文件。

现在,使用下面给出的命令运行JAR文件:

java jar <JARFILE> 

现在,该应用程序已在Tomcat端口9090上启动,如下所示-

Tomcat Port 9090 Output

现在,从Web浏览器中点击以下URL,然后查看Admin Server UI。

http:// localhost:9090/

Web Browser Admin Server UI

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

趣谈Linux操作系统 -〔刘超〕

ZooKeeper实战与源码剖析 -〔么敬国〕

Kafka核心源码解读 -〔胡夕〕

分布式金融架构课 -〔任杰〕

代码之丑 -〔郑晔〕

手把手带你写一个Web框架 -〔叶剑峰〕

大厂设计进阶实战课 -〔小乔〕

运维监控系统实战笔记 -〔秦晓辉〕

AI大模型之美 -〔徐文浩〕

好记忆不如烂笔头。留下您的足迹吧 :)