0%

SpringCloudConfig笔记

对于 springcloud config 的配置

如果eureka的端口不是默认的端口,需要把端口写回配置文件,因为项目启动是先去找eureka,再获取配置

1
2
3
4
eureka:
client:
service-url:
defaultZone: http://localhost:8762/eureka/

使用springcloud bus的bus-refresh接口需要springboot暴露该接口

需要在controller加@RefreshScope

1
2
3
4
5
management:
endpoints:
web:
exposure:
include: "*"

添加webhook需要添加如下依赖

1
2
3
4
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-monitor</artifactId>
</dependency>

springcloud stream 同一个服务input信道和output信道不能一样。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public interface StreamClient {

String INPUT = "input";

String OUTPUT = "output";

@Input(StreamClient.INPUT)
SubscribableChannel input();

@Output(StreamClient.OUTPUT)
MessageChannel output();

/*@Input(StreamClient.INPUT2)
SubscribableChannel input2();

@Output(StreamClient.INPUT2)
MessageChannel output2();*/
}

Gson转list对象的方法

1
List<ProductInfo> productInfoList = new Gson().fromJson(message,new TypeToken<List<ProductInfo>>(){}.getType());

对于springcloud zuul默认过滤了cookie

zuul:

routes:
myProduct:
path: /myProduct/**
serviceId: product
sensitiveHeaders:

使用sensitiveHeaders设置为空即可不过滤cookie

对于springcloud hystrix dashboard

进入的时候,如果你是http,请不要复制他那个请求,他那个请头是https,改成http,并且把这段代码写入即可

1
2
3
4
5
6
7
8
9
@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;
}