前言:
最近刚入职,公司使用了SpringCloud,之前有了解过SpringCloud,但是长时间不去搭建不去使用很容易就忘了,因此空闲时间重新复习一下SpringCloud。但是之前开的SpringCloud的版本可能有点低,公司现在用的 " Greenwich.RELEASE "的版本,SpringBoot使用了“ 2.1.x ”的版本,算是比较新了,因此在使用 Hystrix-Dashboard 的时候会有点坑,因此想把踩到的坑记录下来,让更多的人避开这个坑,废话不多说,开始了!
一、创建 Hystrix-Dashboard 监控服务:springcloud-hystrix-dashboard
- 工程pom依赖
<?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 https://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.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gxc.test</groupId>
<artifactId>springcloud-hystrix-dashboard</artifactId>
<version>1.0.0</version>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
- yml配置文件
server:
port: 10000
spring:
application:
name: springcloud-hystrix-dashboard
- 在启动类上添加注解 @EnableHystrixDashboard
@EnableHystrixDashboard
@SpringBootApplication
public class HystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(HystrixDashboardApplication.class, args);
}
}
- 启动!浏览器访问地址:http://localhost:10000/hystrix ,如下图:
二、创建Eureka注册中心:springcloud-eureka-server
有读者可能会问:不是说玩 Hystrix-Dashboard 吗?为啥还要用到Eureka?
答:请耐心往下看,这也是我为什么题目说的坑...
- 工程pom依赖
<?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 https://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.1.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.gxc.test</groupId>
<artifactId>springcloud-hystrix-dashboard</artifactId>
<version>1.0.0</version&