【发布时间】:2019-10-07 20:10:14
【问题描述】:
我正在使用@PropertySource 来配置一个配置类:
@Configuration
@PropertySource("classpath:/mongo-${env}.properties")
public class MongoConfiguration {
mongo-${env}.properties 文件位于类路径中。 这很好用。
我现在正在使用 Spring Cloud Config 将配置外部化到 Git: 所有 application.yml 文件都已迁移。 但是我不知道这是否可能以及如何将属性文件外部化,如@PropertySource 中声明的文件。
我做了什么: 我试图在 Git 中将 mongo-prod.properties 重命名为 application-prod.properties。 然后我将@PropertySource 更改为:
@PropertySource("file:///C://.../config-repo/application-prod.properties")
这是存储库的本地副本。这可行,但这只是一个硬编码的解决方案。
有更清洁的解决方案吗?
【问题讨论】:
标签: spring spring-boot spring-cloud spring-cloud-config