Sprin Boot2.0开启hystrix-dashboard出现Unable to connect to Command Metric Stream

问题描述

开启hystrix-dashboard后,显示Unable to connect to Command Metric Stream.,页面一直如下:
Sprin Boot2.0开启hystrix-dashboard出现Unable to connect to Command Metric Stream_第1张图片

环境说明

应有的pom.xml依赖如下:


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0modelVersion>
	<parent>
		<groupId>org.springframework.bootgroupId>
		<artifactId>spring-boot-starter-parentartifactId>
		<version>2.1.9.RELEASEversion>
		<relativePath/> 
	parent>
	<groupId>com.examplegroupId>
	<artifactId>consumer--hystrix-dashboardartifactId>
	<version>0.0.1-SNAPSHOTversion>
	<name>consumer--hystrix-dashboardname>
	<description>Demo project for Spring Bootdescription>

	<properties>
		<java.version>1.8java.version>
		<spring-cloud.version>Greenwich.SR3spring-cloud.version>
	properties>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloudgroupId>
			<artifactId>spring-cloud-starter-netflix-eureka-clientartifactId>
		dependency>
		<dependency>
			<groupId>org.springframework.cloudgroupId>
			<artifactId>spring-cloud-starter-netflix-hystrixartifactId>
		dependency>
		<dependency>
			<groupId>org.springframework.cloudgroupId>
			<artifactId>spring-cloud-starter-netflix-hystrix-dashboardartifactId>
		dependency>
		<dependency>
			<groupId>org.springframework.cloudgroupId>
			<artifactId>spring-cloud-starter-netflix-turbineartifactId>
		dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-actuatorartifactId>
        dependency>
	dependencies>

	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloudgroupId>
				<artifactId>spring-cloud-dependenciesartifactId>
				<version>${spring-cloud.version}version>
				<type>pomtype>
				<scope>importscope>
			dependency>
		dependencies>
	dependencyManagement>

	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.bootgroupId>
				<artifactId>spring-boot-maven-pluginartifactId>
			plugin>
		plugins>
	build>

project>

启动类代码如下:

package com.example.consumerhystrixdashboard;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@EnableHystrixDashboard
@EnableCircuitBreaker
public class ConsumerHystrixDashboardApplication {

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

}

异常原因说明

在依赖和启动类注解齐全的情况下,出现该异常是由于actuator在Spring boot 2.0版本中变更引起.

解决方案

只需修改application.properties文件,在其中添加以下内容即可:

#actuator端口 
management.server.port=9001
#修改访问路径  2.0之前默认是/   2.0默认是 /actuator  可以通过这个属性值修改  
management.endpoints.web.base-path=/actuator
#开放所有页面节点  默认只开启了health、info两个节点
management.endpoints.web.exposure.include=
#显示健康具体信息  默认不会显示详细信息  
management.endpoint.health.show-details=always

修改上述配置后,重启应用,hystrix-dashboard显示正常:
Sprin Boot2.0开启hystrix-dashboard出现Unable to connect to Command Metric Stream_第2张图片

你可能感兴趣的:(#,SpringBoot)