使用版本
<!-- SpringCloud 微服务 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>.0.1</version><type>pom</type><scope>import</scope></dependency>
原因
官方文档中提到了如果要使用bootstrap.yml,需要开启spring.cloud.bootstrap.enabled=true
或者引入spring-cloud-starter-bootstrap
原文链接Config First Bootstrap,但是开启变量需要环境变量或者系统变量这显然不适合我们用作开发
To use the legacy bootstrap way of connecting to Config Server, bootstrap must be enabled via a property or the spring-cloud-starter-bootstrap starter. The property is spring.cloud.bootstrap.enabled=true. It must be set as a System Property or environment variable.
<!-- bootstrap 启动器 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency>
拓展
在学习github开源项目mall-swarm时发现其并没有引用spring-cloud-starter-bootstrap
也可以正常识别bootstarp.yml,此项目中使用的版本为Hoxton.SR5
,查找到对应版本的文档Config First Bootstrap发现此版本并没有这样的要求,推断可能是默认开启的
The default behavior for any application that has the Spring Cloud Config Client on the classpath is as follows: When a config client starts, it binds to the Config Server (through the spring.cloud.config.uri bootstrap configuration property) and initializes Spring Environment with remote property sources.
<!-- SpringCloud 微服务 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Hoxton.SR5</version><type>pom</type><scope>import</scope></dependency>
参考
/flying607/p/14657543.html