2.3 搭建分布式配置中心
配置yml
server:
port: 8888
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/nz1902/SpringCloud-demo1-config.git
search-paths: files
username: 3163779211@qq.com
password: admin123
eureka:
client:
service-url:
defaultZone: http://localhost:8761/eureka
@SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } }
-
启动配置中心服务
-
测试通过分布式配置中心能否访问远程仓库中的文件?
2.4 服务连接到配置中心
-
在具体的服务应用中添加依赖(config client)
-
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency>
配置yml连接到分布式配置中心
spring:
cloud:
config:
uri: http://localhost:8888
name: goods-provider
label: master
#profile:dev