Contents
SpringCloud学习笔记
学习文档来源: https://www.springcloud.cc/spring-cloud-greenwich.html
SpringCloud特点
Spring Cloud为典型的用例提供良好的开箱即用体验,并有良好的扩展机制。
- 分布式/版本化配置
- 服务注册和发现
- 路由
- 服务到服务的呼叫
- 负载均衡
- 断路器
- 分布式消息传递
第一部分 云原生应用程序
Cloud Native是一种应用程序开发风格。
其中Spring Cloud建立在Spring Boot上,涵盖了许多这些功能。Spring Cloud作为两个库提供了更多功能:Spring Cloud Context和Spring Cloud Commons。Spring Cloud Context为Spring Cloud应用程序的ApplicationContext
提供了实用程序和特殊服务(引导上下文,加密,刷新作用域和环境端点)。Spring Cloud Commons是在不同的Spring Cloud实现中使用的一组抽象和通用类(例如Spring Cloud Netflix和Spring Cloud Consul)。
2. Spring Cloud Context:应用程序上下文服务
Spring Boot使用Spring来构建应用程序,他有一套约定俗成的流程与配置。例如,它具有用于公共配置文件的常规位置,并具有用于公共管理和监视任务的端点。
Spring Cloud以此为基础,并添加了一些功能,可能系统中的所有组件都将使用或偶尔需要这些功能。
2.1 Bootstrap Application Context
Spring Cloud应用程序通过创建“ bootstrap ”上下文来运行,该上下文是主应用程序的父上下文。它负责从外部源加载配置属性,并负责解密本地外部配置文件中的属性。这两个上下文共享一个Environment
,它是任何Spring应用程序的外部属性的来源。
eg:
bootstrap.yml。
spring:
application:
name: foo
cloud:
config:
uri: ${SPRING_CONFIG_URI:http://localhost:8888}
如果应用程序需要来自服务器的任何特定于应用程序的配置,则最好设置spring.application.name
(在bootstrap.yml
或application.yml
中)。
为了将属性spring.application.name
用作应用程序的上下文ID,必须在bootstrap.[properties | yml]
中进行设置。
如果要检索特定的配置文件配置,还应该在bootstrap.[properties | yml]
中设置spring.profiles.active
。
您可以通过设置spring.cloud.bootstrap.enabled=false
来完全禁用引导过程(例如,在系统属性中)。
发表回复