一、備注說明:
1.經過幾天的努力,終于完成了一份簡易的spring-cloud套餐。主要涉及:
a.注冊中心-eureka;
b.配置中心-config;
c.監控中心-turbine;
d.路由中心-zuul;
e.微服務-user使用者服務;
f.微服務-news資訊服務;
2.版本說明:
spring-boot:2.0.1.RELEASE
spring-cloud:Finchley.M9
二、踩坑記錄:
1.斷路器hystrix、hystrix-dashboard的依賴需要用Netflix下的
否則會引入不成功依賴,導緻@EnableHystrix @EnableHystrixDashboard注解找不到:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
<version>${spring-cloud.netflix.version}</version>
</dependency>
<artifactId>spring-cloud-starter-netflix-hystrix-dashboard</artifactId>
2.通路斷路器監控頁面時,需要在入口啟動類新增urlMapping,否則會一直加載不到資料:
@Bean
public ServletRegistrationBean getServlet(){
HystrixMetricsStreamServlet streamServlet = new HystrixMetricsStreamServlet();
ServletRegistrationBean registrationBean = new ServletRegistrationBean(streamServlet);
registrationBean.setLoadOnStartup(1);
registrationBean.addUrlMappings("/actuator/hystrix.stream");
registrationBean.setName("HystrixMetricsStreamServlet");
return registrationBean;
}
3.配置中心和消息總線互通時,需要修改配置項:
management:
endpoints:
web:
exposure:
include: bus-refresh
在發送更新告知請求時,需要get請求,位址為:
http://localhost:40001/actuator/bus-refresh
感謝之前填坑的技術朋友,讓我可以在遇到坑的時候,找到資料。本文主要是記錄總結下,填坑的解決方法均來源于網絡。