如何外化"spring.config.location"?
How to externalize "spring.config.location"?
我正在尝试告诉 Spring 在哪里可以找到我的外部 "application.properties" 文件。我最终的可部署工件是一个 war 文件,我正在使用 tomcat 进行测试。它不是嵌入了 tomcat 的可执行 jar。我已将 "application.properties" 放在根驱动器或文件系统之外的新 "config" 目录中。
当我将它放在我的@Configuration class 中时,它会抛出一个 FileNotFoundException。
@PropertySource(name = "spring.config.location", value = "/config", ignoreResourceNotFound = false)
Caused by: java.io.FileNotFoundException: class path resource
[config/] cannot be opened because it does not exist
新的 "config" 目录存在于我的本地 Windows 7 服务器上,并且存在 "application.properties" 文件。我究竟做错了什么?
我还尝试设置一个 Windows7 系统环境变量,名称为 "spring.config.location",值为“\config”。那也失败了,有同样的错误。
我应该注意到我的父 maven 模块是 spring-boot-starter-parent:1.3.5-RELEASE。
问题已使用以下配置位置解决
"file:///c:/../config/application.properties".
可以使用实际位置前面的 "file:" 指令从类路径外部加载 属性 文件。
我正在尝试告诉 Spring 在哪里可以找到我的外部 "application.properties" 文件。我最终的可部署工件是一个 war 文件,我正在使用 tomcat 进行测试。它不是嵌入了 tomcat 的可执行 jar。我已将 "application.properties" 放在根驱动器或文件系统之外的新 "config" 目录中。
当我将它放在我的@Configuration class 中时,它会抛出一个 FileNotFoundException。
@PropertySource(name = "spring.config.location", value = "/config", ignoreResourceNotFound = false)
Caused by: java.io.FileNotFoundException: class path resource [config/] cannot be opened because it does not exist
新的 "config" 目录存在于我的本地 Windows 7 服务器上,并且存在 "application.properties" 文件。我究竟做错了什么?
我还尝试设置一个 Windows7 系统环境变量,名称为 "spring.config.location",值为“\config”。那也失败了,有同样的错误。
我应该注意到我的父 maven 模块是 spring-boot-starter-parent:1.3.5-RELEASE。
问题已使用以下配置位置解决 "file:///c:/../config/application.properties".
可以使用实际位置前面的 "file:" 指令从类路径外部加载 属性 文件。