码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • Spring Cloud Config Server 和Client 基本配置


    官网:http://cloud.spring.io/spring-cloud-config/single/spring-cloud-config.html#_quick_start

    Git 文件配置创建

    我的服务地址(码云):https://gitee.com/xiechenxuyuan/SpringCouldConfig

    如下:

    Spring Cloud Config Server

    1、创建项目

    从spring官网 :http://start.spring.io/创建一个简单的spring boot项目

    2、添加依赖

    
    		
    			org.springframework.boot
    			spring-boot-starter-web
    		
    		
    			org.springframework.cloud
    			spring-cloud-starter-config
    		
    		
    			org.springframework.cloud
    			spring-cloud-config-server
    		
            
    		
    			
    			
    			
    		
    		
    			org.springframework.boot
    			spring-boot-starter-test
    			test
    		
    	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    3、在application.properties 里添加配置

    #服务端口
    server.port=8091
    #服务名称
    spring.application.name=configServer
    #服务注册中心 ,需要eureka 可以解开
    #eureka.client.service-url.defaultZone=http://localhost:9761/eureka/
    #服务的git仓库地址
    spring.cloud.config.server.git.uri=https://gitee.com/xiechenxuyuan/SpringCouldConfig
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    4、启动类添加注解

    @SpringBootApplication
    @EnableConfigServer
    //@EnableDiscoveryClient  //eurekaClinet注解
    public class SpringCloudConfigServerApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(SpringCloudConfigServerApplication.class, args);
    	}
    
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    测试:http://localhost:8091/application/dev

    访问资源的形式如下:

    The HTTP service has resources in the following form:
    /{application}/{profile}[/{label}]
    /{application}-{profile}.yml
    /{label}/{application}-{profile}.yml
    /{application}-{profile}.properties
    /{label}/{application}-{profile}.properties

    {
        "name": "application",
        "profiles": [
            "dev"
        ],
        "label": null,
        "version": "e0fa159ad38a0a064963b37a6abca0f7bfeb2fac",
        "state": null,
        "propertySources": [
            {
                "name": "https://gitee.com/xiechenxuyuan/SpringCouldConfig/application-dev.properties",
                "source": {
                    "name": "shuaiqi",
                    "age": "22",
                    "version": "dev"
                }
            }
        ]
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    Spring Cloud Config Client

    1、创建基本的项目 ,如上

    2、添加依赖

    
    		
    			org.springframework.boot
    			spring-boot-starter-web
    		
    		
    			org.springframework.cloud
    			spring-cloud-starter-config
    		
    		
    			org.springframework.cloud
    			spring-cloud-config-server
    		
    
    		
    			
    			
    			
    		
    		
    			org.springframework.boot
    			spring-boot-starter-test
    			test
    		
    	
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25

    3、创建bootstrap.properties

    #文件夹名
    spring.application.name=application
    # dev根据具体情况来修改
    spring.cloud.config.profile=dev
    spring.cloud.config.label=master
    #eureka.client.service-url.defaultZone=http://localhost:9761/eureka/
    spring.cloud.config.uri= http://localhost:8091/
    #spring.cloud.config.discovery.enabled=true
    #文件服务的服务名
    spring.cloud.config.discovery.service-id=configServer
    server.port=2008
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    4、启动项添加注解 和测试内容

    @RestController
    @SpringBootApplication
    //@EnableDiscoveryClient // 表示这是一个Eureka客户端
    public class SpringCloudConfigClientApplication {
    
    	public static void main(String[] args) {
    		SpringApplication.run(SpringCloudConfigClientApplication.class, args);
    	}
    
    	@Value("${name}")
    	String name;
    
    	@Value("${version}")
    	String version;
    
    	@Value("${age}")
    	String age;
    	@RequestMapping("/")
    	public String home() {
    		return "name:" + name+",age:"+age+",version:"+version;
    	}
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    测试:输入localhost:2008

  • 相关阅读:
    【vue.js】路由使用与Node.js下载安装之环境配置
    leetcode marathon [复习] 8.24 - 9道
    【数据结构】树的基础知识及三种存储结构
    treevalue——Master Nested Data Like Tensor
    java-net-php-python-jspm校园闲置物品拍卖系统计算机毕业设计程序
    通过霍夫直线检测方式获取直线,自定义提取直线(提取出两条接近平行的直线),将直线进行拟合
    将 WSL 安装到C盘以外的位置
    运动学模型(二)----轮速计 & 后轮速差模型
    传染病学模型 | Matlab实现SEIR传染病学模型 (SEIR Epidemic Model)
    MybatisPlus【SpringBoot】 7 通用枚举
  • 原文地址:https://blog.csdn.net/iijik55/article/details/126496801
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号