springcloud-config client配置文件为什么要用bootstrap命名
2016-11-24 18:21
2306 查看
搭建srpingcloud-config server端的时候,配置文件可以用application.yml 或 application.properties
但是为什么在config client端却要使用bootstrap.yml或bootstrap.properties呢?
因为bootstrap.properties的加载是先于application.properties的。
在springcloud-config的源码包spring-cloud-config-server-1.1.0.RELEASE.jar中的ConfigServerBootstrapConfiguration类中可以看到如下:
/**
* Bootstrap configuration to fetch external configuration from a (possibly remote)
* {@link EnvironmentRepository}. Off by default because it can delay startup, but can be
* enabled with <code>spring.cloud.config.server.bootstrap=true</code>. This would be
* useful, for example, if the config server were embedded in another app that wanted to
* be configured from the same repository as all the other clients.
*
* @author Dave Syer
* @author Roy Clarkson
*/
@Configuration
public class ConfigServerBootstrapConfiguration {
@ConditionalOnProperty("spring.cloud.config.server.bootstrap")
@Import(EnvironmentRepositoryConfiguration.class)
protected static class LocalPropertySourceLocatorConfiguration {
@Autowired
private EnvironmentRepository repository;
@Autowired
private ConfigClientProperties client;
@Autowired
private ConfigServerProperties server;
@Bean
public EnvironmentRepositoryPropertySourceLocator environmentRepositoryPropertySourceLocator() {
return new EnvironmentRepositoryPropertySourceLocator(this.repository,
this.client.getName(), this.client.getProfile(), getDefaultLabel());
}
private String getDefaultLabel() {
if (StringUtils.hasText(this.client.getLabel())) {
return this.client.getLabel();
}
else if (StringUtils.hasText(this.server.getDefaultLabel())) {
return this.server.getDefaultLabel();
}
return null;
}
}
}
@ConditionalOnProperty("spring.cloud.config.server.bootstrap")
看该注解的源码。默认是false的。
但是为什么在config client端却要使用bootstrap.yml或bootstrap.properties呢?
因为bootstrap.properties的加载是先于application.properties的。
在springcloud-config的源码包spring-cloud-config-server-1.1.0.RELEASE.jar中的ConfigServerBootstrapConfiguration类中可以看到如下:
/**
* Bootstrap configuration to fetch external configuration from a (possibly remote)
* {@link EnvironmentRepository}. Off by default because it can delay startup, but can be
* enabled with <code>spring.cloud.config.server.bootstrap=true</code>. This would be
* useful, for example, if the config server were embedded in another app that wanted to
* be configured from the same repository as all the other clients.
*
* @author Dave Syer
* @author Roy Clarkson
*/
@Configuration
public class ConfigServerBootstrapConfiguration {
@ConditionalOnProperty("spring.cloud.config.server.bootstrap")
@Import(EnvironmentRepositoryConfiguration.class)
protected static class LocalPropertySourceLocatorConfiguration {
@Autowired
private EnvironmentRepository repository;
@Autowired
private ConfigClientProperties client;
@Autowired
private ConfigServerProperties server;
@Bean
public EnvironmentRepositoryPropertySourceLocator environmentRepositoryPropertySourceLocator() {
return new EnvironmentRepositoryPropertySourceLocator(this.repository,
this.client.getName(), this.client.getProfile(), getDefaultLabel());
}
private String getDefaultLabel() {
if (StringUtils.hasText(this.client.getLabel())) {
return this.client.getLabel();
}
else if (StringUtils.hasText(this.server.getDefaultLabel())) {
return this.server.getDefaultLabel();
}
return null;
}
}
}
@ConditionalOnProperty("spring.cloud.config.server.bootstrap")
看该注解的源码。默认是false的。
相关文章推荐
- Spring Cloud Config Client配置说明
- SpringCloud入门之常用的配置文件 application.yml和 bootstrap.yml区别
- Spring Cloud Config RSA简介及使用RSA加密配置文件的方法
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
- Spring Cloud Config 使用本地配置文件
- spring cloud config搭建说明例子(四)-补充配置文件
- spring cloud config 用svn做配置文件仓库
- spring cloud config 用svn做配置文件仓库
- spring cloud config server 使用本地配置文件报错
- SpringCloud之分布式配置中心-本地配置文件(Spring Cloud Config) |第十章 -yellowcong
- SpringCloud系列九:SpringCloudConfig 基础配置(SpringCloudConfig 的基本概念、配置 SpringCloudConfig 服务端、抓取配置文件信息、客户端使用 SpringCloudConfig 进行配置、单仓库目录匹配、应用仓库自动选择、仓库匹配模式)
- Spring cloud config配置文件加密解密
- Spring cloud config 配置文件加密方式
- Spring Cloud Config - RSA简介以及使用RSA加密配置文件
- Spring Cloud Config配置文件使用对称加密的方法
- spring cloud :统一管理配置文件config
- Spring Cloud Config 的坑:以ssh方式从自己搭建的 git repository 取配置文件
- Spring Cloud Config配置文件加解密
- spring cloud config svn配置多个配置文件