【发布时间】:2017-12-15 07:20:47
【问题描述】:
我有一个 Spring Boot 应用程序,当我从 Intellij 作为 maven 配置运行它时,它可以正常运行。
我有一个使用属性文件定义的环境项目结构。
resources/conf/dev/environment.properties
resources/conf/qa/environment.properties
resources/conf/general.properties
等等
我们的框架以我们选择带有 VM 参数的环境的方式工作。
例如-Denv=dev 或-Denv=qa
将App打包成可执行JAR并尝试运行后,Spring Boot无法识别项目conf路径下的属性文件。
当我查看 JAR 内部时,属性文件位于 {jar-name}.jar\BOOT-INF\classes\conf 下。
错误是:
java.io.FileNotFoundException: conf\general.properties (The system cannot find the path specified)
2017-07-11 10:52:52.864 INFO 17896 --- [main] n.lifecycle: Can't find configuration file [conf\general.properties]
2017-07-11 10:52:52.865 ERROR 17896 --- [main] n.lifecycle: configuration file [null] not found (use default properties as error handling)
我尝试在这里处理文档:https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html 但似乎没有什么可以解决的。 还尝试使用本指南 - http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#executable-jar-launching 但也失败了...
指南将属性文件称为“外部”,但我的属性被打包在 JAR 中。
【问题讨论】:
-
你应该有:resources/conf/application-dev.properties resources/conf/application-ga.properties resources/conf/application.properties 我认为这是春天期望找到的
-
我不认为这是问题所在。当我在使用“spring-boot:run”打包之前运行项目时,它工作正常。更改文件的名称将破坏我们用于管理属性的内部框架。
-
您从 IDE 运行特定配置?或者只是正确地点击 spring boot 主类?
-
没有右键。命令行有 spring-boot:run -Denv=dev 的 Maven 运行配置
标签: java maven spring-boot executable-jar properties-file