免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 5000 | 回复: 1
打印 上一主题 下一主题

Spring Cloud Config客户端使用 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-06-27 10:32 |只看该作者 |倒序浏览
要在应用程序中使用这些功能,只需将其构建为依赖于spring-cloud-config-client的Spring引导应用程序(例如,查看配置客户端或示例应用程序的测试用例)。添加依赖关系的最方便的方法是通过Spring Boot启动器org.springframework.cloud:spring-cloud-starter-config。还有一个Maven用户的父pom和BOM(spring-cloud-starter-parent)和用于Gradle和Spring CLI用户的Spring IO版本管理属性文件。示例Maven配置:
  1. <parent>
  2.        <groupId>org.springframework.boot</groupId>
  3.        <artifactId>spring-boot-starter-parent</artifactId>
  4.        <version>1.3.5.RELEASE</version>
  5.        <relativePath /> <!-- lookup parent from repository -->
  6.    </parent>

  7. <dependencyManagement>
  8.         <dependencies>
  9.                 <dependency>
  10.                         <groupId>org.springframework.cloud</groupId>
  11.                         <artifactId>spring-cloud-dependencies</artifactId>
  12.                         <version>Brixton.RELEASE</version>
  13.                         <type>pom</type>
  14.                         <scope>import</scope>
  15.                 </dependency>
  16.         </dependencies>
  17. </dependencyManagement>

  18. <dependencies>
  19.         <dependency>
  20.                 <groupId>org.springframework.cloud</groupId>
  21.                 <artifactId>spring-cloud-starter-config</artifactId>
  22.         </dependency>
  23.         <dependency>
  24.                 <groupId>org.springframework.boot</groupId>
  25.                 <artifactId>spring-boot-starter-test</artifactId>
  26.                 <scope>test</scope>
  27.         </dependency>
  28. </dependencies>

  29. <build>
  30.         <plugins>
  31.            <plugin>
  32.                <groupId>org.springframework.boot</groupId>
  33.                <artifactId>spring-boot-maven-plugin</artifactId>
  34.            </plugin>
  35.         </plugins>
  36. </build>
复制代码
那么你可以创建一个标准的Spring Boot应用程序,像这个简单的HTTP服务器

  1. @SpringBootApplication
  2. @RestController
  3. public class Application {

  4.     @RequestMapping("/")
  5.     public String home() {
  6.         return "Hello World!";
  7.     }

  8.     public static void main(String[] args) {
  9.         SpringApplication.run(Application.class, args);
  10.     }

  11. }
复制代码
当它运行它将从端口8888上的默认本地配置服务器接收外部配置,如果它正在运行。要修改启动行为,您可以使用bootstrap.properties(如application.properties)更改配置服务器的位置,但用于应用程序上下文的引导阶段),例如

  1. spring.cloud.config.uri: http://myconfigserver.com
复制代码
引导属性将在/env端点中显示为高优先级属性源,例如

  1. $ curl localhost:8080/env
  2. {
  3.   "profiles":[],
  4.   "configService:https://github.com/spring-cloud-samples/config-repo/bar.properties":{"foo":"bar"},
  5.   "servletContextInitParams":{},
  6.   "systemProperties":{...},
  7.   ...
  8. }
复制代码
(名为“configService:<远程存储库的URL> / <文件名>”的属性源包含值为“bar”的属性“foo”,是最高优先级)。

论坛徽章:
0
2 [报告]
发表于 2018-06-27 10:32 |只看该作者
喜欢文章的朋友可以持续关注内容更新~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP