【问题标题】:How to configure application context in Spring?如何在 Spring 中配置应用程序上下文?
【发布时间】:2014-11-17 08:47:11
【问题描述】:

我有应用程序上下文文件,它有这样的字符串:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location">
                <value>main.properties</value>
            </property>
</bean>

这里的 main.properties 是具有动态属性的文件。我想定期更改它们,因此我需要将这些属性存储在 jar 之外的文件系统中。

如何在应用程序上下文中配置多个路径? 或者有其他方法可以解决我的问题?

谢谢。

【问题讨论】:

  • Spring 在他们的框架上有很好的文档。您应该会看到该指南并将其调整为适合您的 bean 和休眠设置。
  • 你可以使用this approach
  • 好的,非常感谢大家。我会尝试实现它。
  • 乔纳森,我觉得这对我有好处。但我不明白如何与 -DappConfig=/path/to/productionDB.properties 相关的“${db.host}”? jvm如何理解属性路径与“${db.host}”参数有关。
  • 在示例中,db.host 将是给定属性文件中的一个条目,例如db.host=localhost 等等...你可以忽略它。 :-)

标签: java spring


【解决方案1】:
<bean id="placeholderProperties"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>file:config/main.properties</value>
            <value>file:config/database.properties</value>
        </list>
    </property>
</bean>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 2023-04-03
    • 2015-08-31
    • 2021-10-11
    • 2017-09-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多