【问题标题】:spring configuration with outside config file带有外部配置文件的弹簧配置
【发布时间】:2012-01-24 16:07:09
【问题描述】:

在我的 applicationContext.xml 我有这个

<context:property-placeholder location="file:#{ systemProperties['outsideConfigFile'] }" />

我使用 -DoutsideConfigFile=/path/to/my/file.properties(已验证)启动我的 tomcat

这似乎不起作用,我明白了

INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from URL [file:#{ systemProperties['outsideConfigFile'] }]

然后

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException:  (No such file or directory)

有没有人知道如何让它工作?我认为问题在于 spring 无法读取给定的系统属性文件。

非常感谢 -- MB

【问题讨论】:

  • 解释一下你的意思,它似乎不起作用?
  • “似乎不起作用”是什么意思?你有例外吗?弹簧不加载?春天说房产没有价值?
  • 更新问题,对不起,好点。

标签: java spring configuration


【解决方案1】:

您的文件路径语法可能是错误的。阅读表 4.1。这个tutorial的资源字符串部分,关注4.7.3. FileSystemResource caveats

【讨论】:

    【解决方案2】:

    正如Spring所指示的,它无法找到该文件。

    尝试使用:-DoutsideConfigFile=file:/path/to/my/file.properties 按照Spring Resource Loader docs。

    【讨论】:

      【解决方案3】:

      使用 ${} 怎么样?由于它是系统属性,因此与从外部文件加载的属性不同,它可以立即可用。你试过吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-16
        • 1970-01-01
        • 2016-07-28
        • 2018-11-27
        • 2011-09-11
        • 2019-09-26
        • 2023-03-24
        相关资源
        最近更新 更多