Spring-Cloud框架搭建总结

断了今生、忘了曾经 提交于 2019-12-01 07:29:39

环境说明

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

https://springbootdev.com/2018/07/14/microservices-introduction-to-spring-cloud-config-server-with-client-examples/

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未定义

解决:

  1. 移除父模块下spring-boot-starter-actuator依赖,将其放到具体业务微服务模块

  2. 移除父模块下spring-boot-starter-web依赖,将其放到具体业务微服务模块

飞机

转载于:https://my.oschina.net/odetteisgorgeous/blog/3042115

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!