使用外部配置文件进行 spring 配置
在我的 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
in my applicationContext.xml I have this
<context:property-placeholder location="file:#{ systemProperties['outsideConfigFile'] }" />
And I start my tomcat with -DoutsideConfigFile=/path/to/my/file.properties (verified)
This does not seem to work, and I get
INFO : org.springframework.beans.factory.config.PropertyPlaceholderConfigurer - Loading properties file from URL [file:#{ systemProperties['outsideConfigFile'] }]
and then
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)
does anyone have anyideas how to get it to work? I think the issue is that spring is not able to read the given system property file.
Thanks a lot
-- MB
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的文件路径语法很可能是错误的。阅读表 4.1。本教程的资源字符串部分和注意4.7.3。文件系统资源注意事项
Chances are that your file path syntax is wrong. Read the Table 4.1. Resource strings section of this tutorial and pay attention to 4.7.3. FileSystemResource caveats
正如 Spring 所指示的,它无法找到该文件。
尝试使用: -DoutsideConfigFile=file:/path/to/my/file.properties 按照 Spring 资源加载器 文档。
As Spring is indicating, it is unable to find the file.
Try using: -DoutsideConfigFile=file:/path/to/my/file.properties as per Spring Resource Loader docs.
使用 ${} 怎么样?由于它是系统属性,因此与从外部文件加载的属性不同,它可以立即使用。你尝试过吗?
What about using ${}? Since it's a System property, it's available immediately unlike properties loaded from an external file. Have you tried that?