我需要将一些属性从一个直到程序运行才知道的位置加载到Spring上下文中。
所以我想,如果我有一个没有位置的PropertyPlaceholderConfigurer,它将从系统属性中读取my.location,然后我可以在上下文中使用这个位置:property-placeholder
像这样
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
<context:property-placeholder location="${my.location}"/>保罗
发布于 2009-08-21 11:21:09
这里的问题是,您正在尝试使用属性占位符语法来配置属性占位符:)这有点像鸡和蛋的情况-在配置属性占位符之前,spring无法解析您的${my.location}占位符。
这并不令人满意,但您可以通过使用更显式的语法来回避它:
<bean class="org.springframework.beans.factory.config.PropertyPlaceHolderConfigurer">
<property name="location">
<bean class="java.lang.System" factory-method="getenv">
<constructor-arg value="my.location"/>
</bean>
</property>
</bean>发布于 2009-08-21 14:35:04
您可以使用稍微不同的方法来完成此操作。下面是我们如何配置它。我加载了默认属性,然后用可配置位置的属性覆盖了它们。这对我来说非常好用。
<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>https://stackoverflow.com/questions/1311360
复制相似问题