config:
info: "config info for dev(master)"
config:
info: "config info for test(master)"
config:
info: "config info for prod(master)"
config:
info: "config info for dev(dev)"
config:
info: "config info for test(dev)"
config:
info: "config info for prod(dev)"
<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>
server:
port: 8901
spring:
application:
name: config-server
cloud:
config:
server:
git: #配置存储配置信息的Git仓库
uri: https://gitee.com/macrozheng/springcloud-config.git
username: macro
password: 123456
clone-on-start: true #开启启动时直接从git获取配置
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
# 获取配置信息
/{label}/{application}-{profile}
# 获取配置文件信息
/{label}/{application}-{profile}.yml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
server:
port: 9001
spring:
application:
name: config-client
cloud:
config: #Config客户端配置
profile: dev #启用配置后缀名称
label: dev #分支名称
uri: http://localhost:8901 #配置中心地址
name: config #配置文件名称
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
@RestController
public class ConfigClientController {
@Value("${config.info}")
private String configInfo;
@GetMapping("/configInfo")
public String getConfigInfo() {
return configInfo;
}
}
config info for dev(dev)
spring:
cloud:
config:
server:
git:
search-paths: '{application}'
config info for config dir dev(dev)
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
management:
endpoints:
web:
exposure:
include: 'refresh'
@RestController
@RefreshScope
public class ConfigClientController {
@Value("${config.info}")
private String configInfo;
@GetMapping("/configInfo")
public String getConfigInfo() {
return configInfo;
}
}
update config info for config dir dev(dev)
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
erver:
port: 8905
spring:
application:
name: config-security-server
cloud:
config:
server:
git:
uri: https://gitee.com/xxx.git
username: test
password: 123456
clone-on-start: true #开启启动时直接从git获取配置
security: #配置用户名和密码
user:
name: test
password: 123456
server:
port: 9002
spring:
application:
name: config-client
cloud:
config:
profile: dev #启用配置后缀名称
label: dev #分支名称
uri: http://localhost:8905 #配置中心地址
name: config #配置文件名称
username: test
password: 123456
config info for dev(dev)
spring:
cloud:
config:
profile: dev #启用环境名称
label: dev #分支名称
name: config #配置文件名称
discovery:
enabled: true
service-id: config-server
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
config info for config dir dev(dev)