Spring Cloud Config—客户端使用
2017-12-04 16:22
363 查看
要在应用程序中使用这些功能,只需将其构建为依赖于spring-cloud-config-client的Spring引导应用程序(例如,查看配置客户端或示例应用程序的测试用例)。添加依赖关系的最方便的方法是通过Spring Boot启动器
的pom.xml
那么你可以创建一个标准的Spring Boot应用程序,像这个简单的HTTP服务器:
当它运行它将从端口8888上的默认本地配置服务器接收外部配置,如果它正在运行。要修改启动行为,您可以使用
从现在开始,我这边会将近期研发的springcloud微服务云架构的搭建过程和精髓记录下来,帮助更多有兴趣研发spring cloud框架的朋友,希望可以帮助更多的好学者。大家来一起探讨spring cloud架构的搭建过程及如何运用于企业项目。源码来源
org.springframework.cloud:spring-cloud-starter-config。还有一个Maven用户的父pom和BOM(
spring-cloud-starter-parent)和用于Gradle和Spring CLI用户的Spring IO版本管理属性文件。示例Maven配置:
的pom.xml
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <!-- repositories also needed for snapshots and milestones -->
那么你可以创建一个标准的Spring Boot应用程序,像这个简单的HTTP服务器:
@SpringBootApplication @RestController public class Application { @RequestMapping("/") public String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Application.class, args); } }
当它运行它将从端口8888上的默认本地配置服务器接收外部配置,如果它正在运行。要修改启动行为,您可以使用
bootstrap.properties(如
application.properties)更改配置服务器的位置,但用于应用程序上下文的引导阶段),例如
spring.cloud.config.uri: http://myconfigserver.com[/code] 引导属性将在/env端点中显示为高优先级属性源,例如$ curl localhost:8080/env { "profiles":[], "configService:https://github.com/spring-cloud-samples/config-repo/bar.properties":{"foo":"bar"}, "servletContextInitParams":{}, "systemProperties":{...}, ... }
(名为“configService:<远程存储库的URL> / <文件名>”的属性源包含值为“bar”的属性“foo”,是最高优先级)。
注意 | 属性源名称中的URL是git存储库,而不是配置服务器URL。 |
相关文章推荐
- Spring Cloud Config客户端使用
- Spring Cloud Config客户端使用
- **Spring cloud config 配置本地属性供其它客户端使用
- Spring Cloud Config客户端使用
- Spring Cloud(十四)Config 配置中心与客户端的使用与详细
- Spring Cloud Config教程(五)客户端使用
- Spring Cloud Config客户端使用
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
- Spring Cloud Config客户端使用
- Spring Cloud版——电影售票系统<六>使用 Spring Cloud Config 统一管理微服务配置
- .NET Core微服务之基于Steeltoe使用Spring Cloud Config统一管理配置
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务
- Spring Cloud Config 分布式配置中心使用教程
- spring cloud config 学习日记 使用SVN作为仓库
- spring cloud config server使用svn来作为外部配置中心
- springcloud使用ribbon实现客户端负载均衡
- SpringCloud Config Server中{application}等占位符使用场景设置默认拉去分支
- Spring Cloud Config RSA简介及使用RSA加密配置文件的方法
- 使用Spring Cloud Feign作为HTTP客户端调用远程HTTP服务的方法(推荐)
- spring cloud config server 使用本地配置文件报错