1.什么是配置中心
统一管理配置,怏速切换各个环境的配置
相关产品:
百度的 discont
https://github.com/knightliao/disconf
阿里的diamand
https://github.com/takeseem/diamond
springcloud的configs-server:
http://cloud.spring.io/spring-cloud-config/
2.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
3.启动类添加注解@EnableConfigServer
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class ConfigServiceApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServiceApplication.class, args);
}
}
4.修改application.yml配置
server:
port: 9100
eureka:
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
spring:
application:
name: config-server
cloud:
config:
server:
git:
#仓库地址,去掉git
uri: https://gitee.com/YTHeng/config_cloud
#git服务器登录的用户名和密码,我这边使用的是码云
username: 12345678@qq.com
password: 12345678.
#超时时间
timeout: 5
#分支
default-label: master
5.在码云服务器新建仓库和文件
6.访问地址
http://localhost:9100/master/product-service-dev.yml
路径访问方式
/{name}-{profiles}. properties
/{name}-{profiles}.yml
/{name}-{profiles}.json
/{label}/{name]-{profiles].yml
name:服务器名称
profile:环境名称,开发、测试、生产
Lable:仓库分支、默认 master分支
另附:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持亿速云。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。