Spring Boot Admin与Consul共同使用

SBA与Consul同时使用时,会报错,如:Connection Refused: 127.0.0.1:8300。。。。

Consul的基本部署方式请参照:《SpringBoot配置Consul及健康检测》

接下来,进行Admin的配置:

1、修改POM.xml,添加引用后的XML文件如下:


    <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>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>de.codecentric</groupId>
                <artifactId>spring-boot-admin-dependencies</artifactId>
                <version>${spring-boot-admin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

2、修改Application入口工程文件:

@SpringBootApplication
@RestController
@EnableAdminServer
public class HeatMonitorApplication {

    @GetMapping("/health")
    public String healthCheck() {
        return "Hello";
    }

    public static void main(String[] args) {
        SpringApplication.run(HeatMonitorApplication.class, args);
    }

}

注意:如果是参照前文配置的Consul,请在此添加健康监测方法的路径,把"/"路径空出,提供给Admin的页面服务

3、修改application.yml文件

server:
  port: 8000
spring:
  application:
    name: xxxx-monitor

  cloud:
    consul:
      host: 192.168.193.200
      port: 8500
      discovery:
        service-name: ${spring.application.name}
        health-check-path: /health

  # 非常重要,此配置解决报错问题
  boot:
    admin:
      discovery:
        ignored-services: consul

management:
  endpoints:
    web:
      exposure:
        include: "*"
      path-mapping:
        health: /health
      base-path: /actuator
  endpoint:
    health:
      show-details: ALWAYS

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值