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 @ 2024-08-16 09:58  李白与酒  阅读(48)  评论(0编辑  收藏  举报