Spring Boot 简明教程

Spring Boot - Admin Client

要通过 Spring Boot Admin Server 监控和管理微服务应用程序,您应该添加 Spring Boot Admin Starter 客户端依赖项并在应用程序属性文件中指出 Admin Server URI。

For monitoring and managing your microservice application via Spring Boot Admin Server, you should add the Spring Boot Admin starter client dependency and point out the Admin Server URI into the application properties file.

Note - 为了监控应用程序,您应该为您的微服务应用程序启用 Spring Boot Actuator 端点。

Note − For monitoring an application, you should enable the Spring Boot Actuator Endpoints for your Microservice application.

首先,在您的构建配置中添加以下 Spring Boot Admin starter 客户端依赖项和 Spring Boot starter actuator 依赖项。

First, add the following Spring Boot Admin starter client dependency and Spring Boot starter actuator dependency in your build configuration file.

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

Maven users can add the following dependencies in your pom.xml file −

<dependency>
   <groupId>de.codecentric</groupId>
   <artifactId>spring-boot-admin-starter-client</artifactId>
   <version>1.5.5</version>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

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

Gradle users can add the following dependencies in your build.gradle file.

compile group: 'de.codecentric', name: 'spring-boot-admin-starter-client', version: '1.5.5'
compile('org.springframework.boot:spring-boot-starter-actuator')

现在,将 Spring Boot Admin Server URL 添加到您的应用程序属性文件中。

Now, add the Spring Boot Admin Server URL into your application properties file.

对于属性文件用户,在 application.properties 文件中添加以下属性。

For properties file users, add the following properties in the application.properties file.

spring.boot.admin.url = http://localhost:9090/

对于 YAML 用户,在 application.yml 文件中添加以下属性。

For YAML users, add the following property in application.yml file.

spring:
   boot:
      admin:
         url: http://localhost:9000/

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

Now, create an executable JAR file, and run the Spring Boot application by using the following Maven or Gradle commands.

对于 Maven,您可以使用如下命令:−

For Maven, you can use the command as shown −

mvn clean install

“BUILD SUCCESS”之后,您可以在目标目录中找到 JAR 文件。

After “BUILD SUCCESS”, you can find the JAR file under the target directory.

对于 Gradle,您可以使用如下命令:−

For Gradle, you can use the command as shown −

gradle clean build

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

After “BUILD SUCCESSFUL”, you can find the JAR file under the build/libs directory.

现在,运行 JAR 文件,使用所示命令 −

Now, run the JAR file by using the command shown −

java –jar <JARFILE>

现在,应用程序已经启动在 Tomcat 端口 9090 中,具体如下所示:

Now, the application has started on the Tomcat port 9090 as shown −

tomcat port 9090 output

现在,从网络浏览器访问以下网址,查看您的 Spring Boot 应用程序已经注册于 Spring Boot Admin Server。

Now hit the following URL from your web browser and see your spring Boot application is registered with Spring Boot Admin Server.

spring boot admin server

现在,点击 Details 按钮,然后在 Admin Server UI 中查看执行器端点。

Now, click the Details button and the see the actuator endpoints in Admin Server UI.

actuator endpoints in admin server ui