spring cloud config 读取配置中心

本文介绍了如何在Spring Cloud中配置和使用配置中心服务。首先,通过在服务的pom文件添加依赖和设置yml配置,启用配置中心。接着,客户端服务同样需要添加依赖,并配置相关yml文件。为了读取配置文件,提供了三种HTTP请求方式:1) 读取properties文件,通过应用名和profile;2) 读取json文件,指定路径和分支;3) 读取特定文件夹下的文件,提供文件夹和文件名。
摘要由CSDN通过智能技术生成

spring cloud 读取配置中心

一、配置中心服务:

  1. pom文件添加依赖:
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
		</dependency>
  1. yml配置文件:
		spring:
		  application:
			name: config-center
		  cloud:
			config:
			  server:
				git:
				  uri: http://10.0.0.000:10000/root/config.git  ## 配置中心的git地址,存放各种配置文件
				  username: root		## 该git项目的账户
				  password: 123456		## 该git项目的密码
		  profiles:
			active: pro
		server:
		  port: 1111 	##配置中心的端口
  1. 启动类添加注解EnableConfigServer,表明该服务是配置中心:
		@SpringBootApplication
		@EnableConfigServer
		public class ConfigCenterApplication extends SpringBootServletInitializer {

			public static void main(String[] args) {
				SpringApplication.run(ConfigCenterApplication.class, arg
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值