我正在尝试使用属性占位符来加载一些属性文件,并且我想使用系统属性指定其中一个文件的名称,以便我可以根据我的应用程序运行的环境加载不同的文件。
最初我尝试了以下方法:
<context:property-placeholder location="classpath:environment_common.properties,classpath:environment_${app_env}.properties" />
我验证了系统属性(app_env)设置正确(例如,“bar”),但 Spring 正在加载错误的文件(例如,environment_foo.properties)。
接下来我尝试使用SpEL:
<context:property-placeholder
location="#{ 'classpath:environment_common.properties,classpath:environment_'.concat(systemProperties['app_env'] }.properties) }" />
但似乎context:property-placeholder
不支持SpEL:
java.io.FileNotFoundException: Could not open ServletContext resource [/#{'classpath:environment_common.properties]
它看起来好像context:property-placeholder
有自己的解析器来寻找逗号来分隔多个属性文件,但它不是首先将值传递给 SpEL 来评估它。
我应该如何使用context:property-placeholder
,还是应该绕过它PropertyPlaceHolderConfigurer
直接使用?