6

我有这个属性设置

<bean id="preferencePlaceHolder"
      class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer">
    <property name="locations" ref="propertiesLocations" />
</bean>
<beans profile="dev, testing">
    <util:list id="propertiesLocations">
        <value>classpath:runtime.properties</value>
        <value>classpath:dev.properties</value>
    </util:list>
</beans>
...

runtime.properties 中有一个属性,就像这样

doImportOnStartup=false

我想偶尔这样做

mvn jetty:run -DdoImportOnStartup=true

并让系统属性优先。我怎样才能做到这一点?谢谢。

4

1 回答 1

3

这可能不是您想要的,但无论如何这是我的属性加载 xml。这些位置是按顺序加载的,因此最后找到的位置将覆盖较早的位置,因此首先是类路径(即 war),然后是文件系统上的 env 特定文件。我更喜欢这种方法,因为它是一个指向外部文件的 1 次配置,但是您只需在需要时更改该外部文件,无需再配置 Spring 或 JVM 参数。最终位置是寻找一个 -Dconfig JVM arg,您可以为覆盖 prop 文件提供完整路径。

希望这可以帮助。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>
<bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer">
    <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
    <property name="searchContextAttributes" value="true" />
    <property name="contextOverride" value="true" />
    <property name="ignoreResourceNotFound" value="true" />
    <property name="locations">
        <list>
            <value>classpath:*.properties</value>
            <value>file:${HOME}/some-env-specific-override.properties</value>
            <value>${config}</value>
        </list>
    </property>
</bean>
于 2013-01-28T16:44:07.830 回答