1、初始化工程
https://start.spring.io/
选config server Eureka Discovery
2、导入IDE改改
入口类上加@EnableConfigServer @EnableDiscoveryClient
application.yml
server:
port: 1027
spring:
application:
name: vishnu-config
cloud:
config:
server:
git:
uri: https://gitee.com/frankawp/vishnu-config
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://localhost:1026/eureka
registry-fetch-interval-seconds: 10
把配置文件传到这个git上。 vishnu-userinfo-dev.yml
启动后在 localhost:1027/vishnu-userinfo/dev 上可以看到这个配置文件就对了
先启动eureka,再启动config项目,能看到注册的config服务
3、使用config配置
回到vishnu-userinfo工程pom.xml加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
拉取config的配置不能放在application.yml里面 将application.yml改为bootstrap.yml配置修改为
server:
port: 1028
spring:
application:
name: vishnu-userinfo
cloud:
config:
fail-fast: true
discovery:
service-id: vishnu-config
enabled: true
profile: dev
label: master
eureka:
instance:
prefer-ip-address: true
lease-renewal-interval-in-seconds: 5
lease-expiration-duration-in-seconds: 20
client:
serviceUrl:
defaultZone: http://localhost:1026/eureka
registry-fetch-interval-seconds: 10
自动从注册中心拉config服务
原文地址:https://www.cnblogs.com/frankawp/p/10116277.html