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