【发布时间】:2019-09-06 12:51:30
【问题描述】:
我使用的是 Spring Boot 2,每个服务都有一个 application.yml。每个 application.yml 定义公共属性以及每个配置文件的特定属性。我想继续使用 Spring Cloud Config。
我希望每个服务从 4 个属性文件中读取属性,这意味着对于配置文件为“dev”的名为“myService”的服务,我希望能够读取:
- config/myService/application-dev.yml(此服务和此配置文件的特定配置)
- config/myService/application.yml(此服务的特定配置,无论哪个配置文件)
- config/application-dev.yml(开发配置文件的特定配置,无论哪个服务)
- config/application.yml(无论哪个服务、哪个配置文件都共享配置)
我创建了一个目录配置。每个服务都有子目录。
然而,当 myService 启动时,只从 git 中检索到 2 个文件。通过 EncryptablePropertySourceConverter 检索第三个文件。 缺少的文件是 config/application.yml。请参阅下面的 myService 日志:
10:27:42.535 [main] INFO o.s.c.b.c.PropertySourceBootstrapConfiguration - Located property source:
10:54:20.449 [main] INFO o.s.c.b.c.PropertySourceBootstrapConfiguration - Located property source: CompositePropertySource {name='configService',
propertySources=[MapPropertySource {name='configClient'},
MapPropertySource {name='ssh://git@xxx:7999/qi/athena.git/config/myService/application-dev.yml'},
MapPropertySource {name='ssh://git@xxx:7999/qi/athena.git/config/myService/application.yml'}]}
...
10:54:27.141 [main] INFO c.u.j.EncryptablePropertySourceConverter - Converting PropertySource applicationConfig: [file:./config/application-dev.yml]
[org.springframework.boot.env.OriginTrackedMapPropertySource] to EncryptableMapPropertySourceWrapper
...
10:55:01.469 [main] DEBUG o.s.c.c.c.ConfigServicePropertySourceLocator - Environment myService has 2 property sources with 6 properties.
10:55:01.469 [main] INFO o.s.c.b.c.PropertySourceBootstrapConfiguration - Located property source: CompositePropertySource {name='configService',
propertySources=[MapPropertySource {name='configClient'},
MapPropertySource {name='ssh://git@xxx:7999/qi/athena.git/config/myService/application-dev.yml'},
MapPropertySource {name='ssh://git@xxx:7999/qi/athena.git/config/myService/application.yml'}
配置服务-application.yml:
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: ssh://git@xxx:7999/qi/athena.git
clone-on-start: true
search-paths: 'config/{application}'
default-label: 'feature/ConfigServerDesign'
myService - bootstrap.yml
spring:
application:
name: myService
cloud:
config:
uri: http://localhost:8888
label: 'feature/ConfigServerDesign'
读取config/myService/application.yml和config/myService/application-dev这两个文件。
还会读取共享的 config/application.yml。 https://cloud.spring.io/spring-cloud-config/multi/multi__spring_cloud_config_server.html#_sharing_configuration_with_all_applications 但是文件 config/application.yml 没有被读取。
config/application.yml 和 config/myService/application.yml 有冲突吗?
感谢您的帮助。
【问题讨论】:
标签: spring spring-boot spring-cloud spring-cloud-config