【发布时间】:2018-08-08 09:28:24
【问题描述】:
我有一个 spring 项目(不是 spring boot),其中有 3 个基于环境的属性文件和 1 个主属性文件。 每次启动时都会读取 application.properties,但我希望在使用 -Denv=dev 运行应用程序时读取 application-dev.properties。
我使用 gradle tomcatRunWar 运行应用程序,配置如下: run configurations
我的 commonContext.xml 是这样设置的:
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ">
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="ignoreResourceNotFound" value="true"/>
<property name="locations">
<list>
<value>classpath:conf/application.properties</value>
<value>classpath:conf/application-#{systemProperties['env']}.properties</value>
</list>
</property>
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<property name="searchSystemEnvironment" value="true"/>
但在日志中它只是说“conf/application-.properties 无法打开,因为它不存在”,因此它不会读取我使用 -Denv=dev 设置的值。
我已经阅读了一些其他主题,但没有看到这样的问题。 设置环境变量有效,但这不是一个可以使用的选项。
【问题讨论】:
标签: java spring properties configuration