我有一个Spring Boot应用程序从Spring Cloud配置服务器(本机模式)获取配置。在由配置服务器加载的配置位置的基础application.yml文件包含以下内容:当从Spring Cloud Config服务器获取配置时,弹簧配置文件没有正确排序
eureka:
client:
service-url:
defaultZone: ${BOOT_EUREKA_LOCATIONS:http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka}
register-with-eureka: true
---
spring:
profiles: test
eureka:
client:
register-with-eureka: false #no registration on Eureka when testing
service-url:
defaultZone: ${BOOT_EUREKA_LOCATIONS:http://sparky:8761/eureka}
击球时对配置服务器端点(http://mygateway/config-server/myapp/test),我回来在运行“的myapp”应用以下轮廓 “测试”:
{
"name": "myapp",
"profiles": [
"test"
],
"label": null,
"version": null,
"state": null,
"propertySources": [
{
"name": "file:////wherever/application.yml#test",
"source": {
"spring.profiles": "test",
"eureka.client.register-with-eureka": false,
"eureka.client.service-url.defaultZone": "${BOOT_EUREKA_LOCATIONS:http://sparky:8761/eureka}"
}
},
{
"name": "file:////whereever/application.yml",
"source": {
"eureka.client.service-url.defaultZone": "${BOOT_EUREKA_LOCATIONS:http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka}"
当在测试配置文件中运行对myApp,eureka.client.service-url.defaultZone的值是http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka,这是出乎意料的。
我会期望在测试配置文件中的条目覆盖它(如果你有本地application.yml的话)。关于在myApp中使用该值时为什么我不会从“测试”配置文件获取值?
我的目的是在顶部添加“默认”值,并使“配置文件”覆盖任何非标准默认值。
更新: 对myApp/ENV不显示“application.yml#考”载,但它显示了测试配置文件,但只有默认值从配置服务器(而不是那些#TEST)返回:
{
"profiles": [
"test"
],
"server.ports": {
"local.server.port": 7761
},
"configService:file:////wherever/application.yml": {
"eureka.client.service-url.defaultZone": "http://instance1.localhost:7761/eureka,http://instance2.localhost:7762/eureka,http://instance3.localhost:7763/eureka"
myApp'/ env'说什么? – spencergibb
添加了其他信息以回答上面的问题。伟大的问题,并可能导致答案。 – LetsBeFrank