1

我有一个弹簧上下文配置。在此配置中,我有以下属性占位符:

<context:property-placeholder location="classpath:my_prop_file.properties,
    classpath:my_prop_file-${envTarget}.properties" ignore-resource-not-found="true"/>

这个想法是,所有属性都设置在 my_prop_file.properties 中,而在其他属性文件中我只覆盖一些(my_prop_file-env1.properties、my_prop_file-env2.properties 等)。这工作正常。问题是当我在启动时省略了 vm 参数 -DenvTarget 。有没有办法默认呢?当未设置该值时,我收到:

Could not resolve placeholder 'envTarget' in string value 
4

1 回答 1

0

您可以创建一个空的 my_prop_file-local.properties 文件并修改您的属性占位符定义以包含 envTarget 的默认值。

<context:property-placeholder 
   location="classpath:my_prop_file.properties, classpath:my_prop_file-${envTarget:local}.properties" 
   ignore-resource-not-found="true"/>
于 2018-05-25T12:48:35.683 回答