SpringBootAdmin集成

原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/18362342

 

两个服务,一个SpringBootAdmin服务,一个SpringBoot服务

SpringBootAdmin服务

Maven Dependency

复制代码
<?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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.18</version>
    </parent>

    <groupId>org.fool</groupId>
    <artifactId>springbootadmin</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

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

        <dependency>
            <groupId>de.codecentric</groupId>
            <artifactId>spring-boot-admin-starter-server</artifactId>
            <version>2.7.16</version>
        </dependency>
    </dependencies>
</project>
复制代码

 Note: SpringBootAdmin服务中加载的依赖是spring-boot-admin-starter-server

 

application.yml

server:
  port: 8081
  servlet:
    context-path: /monitor

 

Application.java

复制代码
package org.fool.springbootadmin;

import de.codecentric.boot.admin.server.config.EnableAdminServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(Application.class);
    }
}
复制代码

Note: @EnableAdminServer注解必须加上 

 

启动服务

 

SpringBoot服务

Maven Dependency

复制代码
...
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>spring-boot-admin-starter-client</artifactId>
    <version>2.7.16</version>
</dependency>
...
复制代码

Note: SpringBoot服务中加载的依赖是spring-boot-admin-starter-client

 

application.yml

复制代码
server:
  port: 8080

management:
  endpoints:
    enabled-by-default: true
    web:
      exposure:
        include: "*"
  endpoint:
    health:
      show-details: always
      enabled: true

spring:
  application:
    name: testspringboot
  boot:
    admin:
      client:
        url: http://localhost:8081/monitor
        instance:
          prefer-ip: true
复制代码

 

启动服务后

 

查看监控

 

posted @   李白与酒  阅读(82)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
历史上的今天:
2021-08-16 Flink Sink Kafka
点击右上角即可分享
微信分享提示