环境说明
spring cloud使用版本 Greenwich.SR1
,2019/4/24 最新版
遇到问题
修改server.port后,端口变更不起作用,总是8080
src/java/resources应该和rc/java/java在同一个层级,否则boot读取不到配置信息
RestTemplate UnknownHostException
https://stackoverflow.com/questions/37159662/microservices-resttemplate-unknownhostexception
https://github.com/KenavR/spring-boot-microservices-example
在RestTemplate的bean上还要加上@LoadBalanced,可能原因是不会默认创建一个RestTemplate实例
配置中心值无法获取 Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'zuul.routes.dogs.url' in value "${zuul.routes.dogs.url}"
访问路径 http://localhost:8888/app/dev
配置中心参考及DEMO
http://www.ityouknow.com/springcloud/2017/05/22/springcloud-config-git.html
https://github.com/chathurangat/spring-cloud-config-example
更改spring-config中的值,使用方(加了@RefreshScope注解)生效
- 修改test值
- 使用方调用 /actuator/refresh (POST请求 参数和返回设置成json)
@RestController
@RefreshScope
public class OrderController {
@Value("${test}")
private String name;
@GetMapping("call")
public JSONObject call(){
JSONObject jsonObject = new JSONObject();
jsonObject.put("url",name);
return jsonObject;
}
}
zipkin
https://github.com/openzipkin/sleuth-webmvc-example
http://www.ityouknow.com/springcloud/2018/02/02/spring-cloud-sleuth-zipkin.html
hytrix-dashbord
打开 http://localhost:7979/hystrix
输入http://localhost:7979/actuator/hystrix.stream
多个节点实现集群监控需要使用turbine
springCloud gateway
报错:ServerCodecConfigurer
bean未定义
解决:
-
移除父模块下
spring-boot-starter-actuator依赖
,将其放到具体业务微服务模块 -
移除父模块下
spring-boot-starter-web
依赖,将其放到具体业务微服务模块