SpringCloud(Finchley.SR1)整合hystrixdashboard
一、三个子模块模块eureka-server、dept-provider、dept-consumer-hystrix-dashboard
二、在dept-consumer-hystrix-dashboard中导入依赖(注意:如果想要监控多个服务,那么每个服务提供者的模块中都要导入actuator的依赖)
<!--hystrix-dashboard依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<!-- actuator监控信息完善 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
三、在dept-provider中导入依赖:
<!--eureka client依赖 因为要将服务注册进eureka中所以导了这个依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<!--hystrix依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<!--hystrix-dashboard依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<!-- actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
四、eureka-server中导入依赖:
<!--eureka server依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
五、dept-provider的启动类注解:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringBootApplication
@EnableEurekaClient //将服务注册进eureka
@EnableCircuitBreaker //开启hystrix熔断器
@EnableHystrixDashboard //开启服务监控
public class MicroservicecloudProviderDeptHystrix8001Application {
public static void main(String[] args) {
SpringApplication.run(MicroservicecloudProviderDeptHystrix8001Application.class, args);
}
}
六、dept-consumer-hystrix-dashboard启动类注解:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableHystrixDashboard
public class MicroservicecloudConsumerHystrixDashboardApplication {
public static void main(String[] args) {
SpringApplication.run(MicroservicecloudConsumerHystrixDashboardApplication.class, args);
}
}
七、eureka-server启动类注解:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;
@SpringBootApplication(exclude= {DataSourceAutoConfiguration.class})
@EnableEurekaServer
public class MicroservicecloudEureka7001Application {
public static void main(String[] args) {
SpringApplication.run(MicroservicecloudEureka7001Application.class, args);
}
}
八、启动顺序:eureka-server、dept-provider、consumer-hystrix-dashboard
九、测试(略)。。。。
愿每天你,都昨天优秀一点!!!