Spring Boot外部application.properties [英] Spring boot external application.properties
问题描述
我正在开发Spring Boot应用程序
我想用外部文件(例如/etc/projectName/application.properties
)覆盖 src/main/resources/application.properties
中的某些属性./p>
我尝试了几种方法:
-
@PropertySource("file:/etc/projectName/application.properties")
作为ApplicationConfig.java
上的注释 -
spring.config.location =/etc/projectName/application.properties
在我的application.properties中的资源
我用 spring.port
进行了测试.第一种方法仅添加属性,但不覆盖它们.
我总是按照 ,然后在application.properties中指定 I am developing a spring boot application I want to override some properties in I tried several methods: I tested it with I always use Edit: and specify a 这篇关于Spring Boot外部application.properties的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! external.config
.
这将提供覆盖配置的默认路径,通过在命令行中指定-external.config
,它本身仍可以覆盖.
我将 $ {external.config}
定义为系统环境变量,但它也应与application.properties变量一起使用.src/main/resources/application.properties
with an external file (e.g. /etc/projectName/application.properties
).
@PropertySource("file:/etc/projectName/application.properties")
as annotation at ApplicationConfig.java
spring.config.location=/etc/projectName/application.properties
in my application.properties in resources
spring.port
. The first method only added properties but didn't override them.--spring.config.location=
in the command line as specified in the documentation, and you can put various files in this, one with default values and another with the overridden ones.
Alternatively, you could also use something like :@PropertySources({
@PropertySource("classpath:default.properties")
, @PropertySource(value = "file:${external.config}", ignoreResourceNotFound = true)
})
external.config
in your application.properties.
This would provide a default path for overridding config, that is still overriddable itself by specifying a --external.config
in the command line.
I use this with ${external.config}
being defined as a system env variable, but it should work with a application.properties variable too.