![](/img/trans.png)
[英]What to set for Spring's @PropertySource when using spring.config.location command line arg?
[英]Springboot @PropertySource with --spring.config.location=/etc/foo/
我想完全外部化我的配置文件,以便每个* .properties文件都位于/ etc / foo /中。
但是我并不想将所有内容都放在一个大的application.properties中,因此我将某些部分分割成单独的* .properties文件。
我该如何告诉@PropertySource它应该完全像其application.properties一样解析给定属性文件的位置,即在我用“ --spring.config”指定的每个直接(可能是多个)中搜索它。位置”?
理想情况下,我的班级看起来会这样:
@Configuration
@PropertySource("dpuProfiles.properties")
@ConfigurationProperties("dpu.profiles")
public class DpuProfilesConfiguration {
...
}
如果我明确指定“ file:/etc/foo/dpuProfiles.properties”,它将起作用。 我无法使用EL工作得到“ $ {spring.config.location} /dpuProfiles.properties”或类似的替换。 由于变量可能包含多个目录,可能也没有意义。
您可以通过在-classpath
指定config(s)目录并将其从类路径指向@PropertySource
对于你的情况
CLASSPATH=just_added_as_an_example_jar.jar:/etc/foo/
-classpath "$CLASSPATH"
但是您需要按如下所示更改@PropertySource
值
@PropertySource({"classpath:dpuProfiles.properties"})
@ConfigurationProperties({"classpath:dpu.profiles"})
注意-上面的示例是从脚本运行的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.