本文介绍spring-cloud配置服务器

spring-cloud开发需要配置文件单独放在一个程序或者服务器管理

server端配置

目录结构

依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.0.5.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>test</groupId>
  12. <artifactId>test</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  19. <java.version>1.8</java.version>
  20. <sping-cloud.version>Edgware.RELEASE</sping-cloud.version>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.cloud</groupId>
  25. <artifactId>spring-cloud-config-server</artifactId>
  26. <version>2.0.2.RELEASE</version>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.boot</groupId>
  30. <artifactId>spring-boot-starter</artifactId>
  31. <version>2.1.2.RELEASE</version>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-starter-test</artifactId>
  36. <scope>test</scope>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.springframework.boot</groupId>
  40. <artifactId>spring-boot-devtools</artifactId>
  41. <scope>runtime</scope>
  42. </dependency>
  43. </dependencies>
  44. <build>
  45. <plugins>
  46. <plugin>
  47. <groupId>org.springframework.boot</groupId>
  48. <artifactId>spring-boot-maven-plugin</artifactId>
  49. </plugin>
  50. </plugins>
  51. </build>
  52. </project>

java代码

  1. package test.test;
  2. import org.springframework.boot.SpringApplication;
  3. import org.springframework.boot.autoconfigure.SpringBootApplication;
  4. import org.springframework.cloud.config.server.EnableConfigServer;
  5. @EnableConfigServer
  6. @SpringBootApplication
  7. public class DemoApplication {
  8. public static void main(String[] args) {
  9. SpringApplication.run(DemoApplication.class, args);
  10. }
  11. }

properties

  1. server.port=9000
  2. spring.cloud.config.server.git.uri=https://github.com/qzruncode/example.git
  3. # 我的git仓库中放了一个spring-cloud-test.properties文件

运行

  1. 执行你的程序,访问 http://localhost:9000/spring-cloud-test.properties
  2. github中的配置文件名称必须以spring-cloud开头,否则无法访问

client端配置

目录结构

依赖

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.0.5.RELEASE</version>
  9. <relativePath/> <!-- lookup parent from repository -->
  10. </parent>
  11. <groupId>test</groupId>
  12. <artifactId>test</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>demo</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  18. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  19. <java.version>1.8</java.version>
  20. <sping-cloud.version>Edgware.RELEASE</sping-cloud.version>
  21. </properties>
  22. <dependencies>
  23. <dependency>
  24. <groupId>org.springframework.boot</groupId>
  25. <artifactId>spring-boot-starter-web</artifactId>
  26. <version>2.0.5.RELEASE</version>
  27. </dependency>
  28. <dependency>
  29. <groupId>org.springframework.cloud</groupId>
  30. <artifactId>spring-cloud-starter-config</artifactId>
  31. <version>2.0.2.RELEASE</version>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-starter</artifactId>
  36. <version>2.1.2.RELEASE</version>
  37. </dependency>
  38. <dependency>
  39. <groupId>org.springframework.boot</groupId>
  40. <artifactId>spring-boot-starter-test</artifactId>
  41. <scope>test</scope>
  42. </dependency>
  43. <dependency>
  44. <groupId>org.springframework.boot</groupId>
  45. <artifactId>spring-boot-devtools</artifactId>
  46. <scope>runtime</scope>
  47. </dependency>
  48. </dependencies>
  49. <build>
  50. <plugins>
  51. <plugin>
  52. <groupId>org.springframework.boot</groupId>
  53. <artifactId>spring-boot-maven-plugin</artifactId>
  54. </plugin>
  55. </plugins>
  56. </build>
  57. </project>

java代码

  1. package test1.test.Controller;
  2. import org.springframework.beans.factory.annotation.Value;
  3. import org.springframework.cloud.context.config.annotation.RefreshScope;
  4. import org.springframework.web.bind.annotation.RequestMapping;
  5. import org.springframework.web.bind.annotation.RestController;
  6. @RefreshScope
  7. @RestController
  8. public class Test {
  9. @Value("${test.data}")
  10. private String data;
  11. @RequestMapping("/")
  12. String home() {
  13. return data;
  14. }
  15. }

properties

  1. application.properties
  2. server.port=8000
  3. bootstrap.properties
  4. spring.application.name=spring-cloud-test
  5. # This is the default:
  6. spring.cloud.config.uri=http://localhost:9000
  7. management.security.enabled=false

运行

  1. 直接访问 http://localhost:8000/ 即可

spring-cloud配置服务器配置的更多相关文章

  1. Spring Cloud 配置服务

    Spring Cloud 配置服务 1. 配置服务简介 产生背景: 传统开发中,我们通常是将系统的业务无关配置(数据库,缓存服务器)在properties中配置,在这个文件中不会经常改变,但随着系统规 ...

  2. 记录一个 spring cloud 配置中心的坑,命令行端口参数无效,被覆盖,编码集问题无法读取文件等.

    spring cloud 配置中心 结合GIT , 可以运行时更新配置文件.发送指令让应用重新读取配置文件. 最近在测试服务器实现了一套,结果CPU 实用率暴增,使用docker compose启动 ...

  3. Spring Cloud配置中心(Config)

    Spring Cloud配置中心(Config) Spring Cloud是现在流行的分布式服务框架,它提供了很多有用的组件.比如:配置中心.Eureka服务发现. 消息总线.熔断机制等. 配置中心在 ...

  4. spring cloud 配置中心

    1. spring cloud配置中心server 1.1 创建git仓库 首先在github上搭建一个存储配置中心的仓库,需要创建两个分支,一个是master,一个是dev分支.自己学习可以用公开库 ...

  5. springcloud(五):Spring Cloud 配置中心的基本用法

    Spring Cloud 配置中心的基本用法 1. 概述 本文介绍了Spring Cloud的配置中心,介绍配置中心的如何配置服务端及配置参数,也介绍客户端如何和配置中心交互和配置参数说明. 配置中心 ...

  6. springcloud(六):Spring Cloud 配置中心采用数据库存储配置内容

    Spring Cloud 配置中心采用数据库存储配置内容 转自:Spring Cloud Config采用数据库存储配置内容[Edgware+] Spring Cloud Server配置中心采用了G ...

  7. Spring Cloud配置中心搭建(集成Git)

    1. 在Github(或其他)创建配置中心仓库bounter-config-repo,然后在仓库创建两个配置文件:simon.properties.susan.properties,链接如下: htt ...

  8. spring cloud 配置zuul实用

    在线演示 演示地址:http://139.196.87.48:9002/kitty 用户名:admin 密码:admin 技术背景 前面我们通过Ribbon或Feign实现了微服务之间的调用和负载均衡 ...

  9. spring cloud配置高可用eureka时遇到的一些坑

    考虑到注册中心的高可用,今天搭建一下eureka集群,并在中途遇到一些小的坑,前前后后花了两个小时来排除,在这里记录一下,以供后面查看. 首先,贴上要达到的效果: 一.起两个eureka模拟集群,在D ...

  10. spring cloud 配置纲要Properties

    名称 默认 描述 encrypt.fail-on-error true 标记说,如果存在加密或解密错误,进程将失败. encrypt.key   对称密钥.作为一个更强大的替代方案,考虑使用密钥库. ...

随机推荐

  1. storm 入门介绍(持续更新)

    storm的集群表面上看和hadoop的集群非常像.但是在Hadoop上面你运行的是MapReduce的Job, 而在Storm上面你运行的是Topology.它们是非常不一样的 — 一个关键的区别是 ...

  2. zzuli 2179 最短路

    2179: 紧急营救 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 9 SubmitStatusWeb Board Descri ...

  3. 在Hive中使用Avro

    作者:过往记忆 | 新浪微博:左手牵右手TEL | 可以转载, 但必须以超链接形式标明文章原始出处和作者信息及版权声明博客地址:http://www.iteblog.com/文章标题:<在Hiv ...

  4. xcrun: error: active developer path (/Users/XJW/Desktop/Xcode.app/Contents/Developer) does not exist, use `xcode-select --switch path/to/Xcode.app` to

    问题: 装了双xcode     删掉低版本  (注意:低版本xcode 开启过项目 )  创建git时报错 解决方法: sudo xcode-select -switch /Applications ...

  5. YCSB benchmark测试cassandra性能——和web服务器测试性能结果类似

    转自:http://www.itdadao.com/articles/c15a531189p0.html http://www.cnblogs.com/bettersky/p/6158172.html ...

  6. ndk+opencv安装+各种错误分析(新版安装,编译不需要Cygwin 和Sequoyah了)

    鼓捣了两三天,终于成功算跑通了一个简单的程序.下面说说具体的安装: 因为从同学那里拷过来的eclipse 就有adt cdt 的插件.所以这两个就不用再安装了.(需要的话自己安装) 具体说下安装过程: ...

  7. 大马猴队-Alpha阶段项目复审

    队名 优点 缺点 名次 菜鸡互坑队 经典游戏,情怀加分. 刷新的苹果会在蛇身上出现  14 菜鸡互啄 利用python语言实现git版本管理,典型用户清晰. 没有很好地分析用户痛点,没有测试计划  4 ...

  8. OC-SEL 和 Class

    [认识选择器]============================================ SEL 1.选择器(SEL)是一个变量类型. 2.选择器用来装成员消息(成员方法) people ...

  9. react antd layout sider

    import React from 'react'; import {Link, withRouter} from 'react-router-dom'; import {Layout, Menu, ...

  10. New Concept English three (31)

    35w/m 45 True eccentrics never deliberately set out to draw attention to themselves. They disregard ...