我需要从程序运行之前我不知道的位置将一些属性加载到 Spring 上下文中。
所以我想,如果我有一个没有位置的 PropertyPlaceholderConfigurer,它会my.location
从系统属性中读取,然后我可以在上下文中使用该位置:property-placeholder
像这样
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<context:property-placeholder location="${my.location}"/>
但这不起作用,也不起作用 location="classpath:${my.location}"
保罗
您可以使用稍微不同的方法来做到这一点。这是我们如何配置它。我加载默认属性,然后使用可配置位置的属性覆盖它们。这对我来说非常有效。
<bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="locations"> <list> <value>classpath:site/properties/default/placeholder.properties </value> <value>classpath:site/properties/${env.name}/placeholder.properties </value> </list> </property> </bean>