【发布时间】:2020-11-09 16:20:21
【问题描述】:
我想让 Spring 加载一个外部配置文件(如果存在),否则使用 src/main/resources 中提供的一次。
当前设置:
src/main/resources/application.properties
src/main/resources/application-dev.properties
src/main/resources/application-prod.properties
/this/is/an/external/dir/application-dev.properties
类似于https://stackoverflow.com/a/27776123/5126654我添加了如下注解:
@EnableFeignClients
@SpringBootApplication
@EnableEncryptableProperties
@PropertySources({ //
@PropertySource("classpath:application.properties"), //
@PropertySource(value = "file:${external.config}", ignoreResourceNotFound = true) //
})
public class Application extends SpringBootServletInitializer {
// ....
}
并且在我的 application.properties 中有以下条目:
external.config=/this/is/an/external/dir/application-dev.properties
我还可以看到外部配置文件被拾取。我遇到的问题是类路径属性文件中的每个条目都会覆盖外部条目。 IE。而不是从 /this/is/an/external/dir/application-dev.properties 条目来自 src/main/resources/application-dev.properties 被占用。
如何修改我的代码以使外部文件覆盖类路径文件的条目?
【问题讨论】:
标签: java spring spring-boot