【发布时间】:2016-12-08 12:09:15
【问题描述】:
我正在接管一个 maven/spring 应用程序,其中配置文件不在类路径中。即 config 文件夹由 jar 旁边的 maven-assembly-plugin 复制,以便在部署应用程序时简化配置。
我的问题是我需要这些配置文件来从我的 IDE (intelliJ) 中运行这个应用程序,当然,Spring 正在抱怨
Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [application.properties] cannot be opened because it does not exist
程序集采用“application-prod”或“application-test”.properties,具体取决于打包时使用的 maven 配置文件,并将其作为“application.properties”复制到 /config 文件夹中,因此在罐子。
我的问题是: 在 Intellij 中运行应用程序时,我应该怎么做才能在类路径中使用这个“application.properties”文件(理想情况下取决于 maven 配置文件),而不会弄乱项目结构?
我想将属性文件作为参数提供给启动器可能是一种解决方案,但我不知道如何。
所以这里是简化的项目结构:
|-- src/
| |-- main/
| | |-- assembly/
| | | |-- bin.xml
| |
| | |-- config/
| | | |-- images/
| | | |-- application-prod.properties
| | | |-- application-test.properties
| |
| | |-- java/...
| | | |-- gui/
| | | | |-- Application.java
| |
| | |-- resources/
| | | |-- context/
| | | | |-- context.xml
| |
| | | |-- fxml/
| | | | |-- welcome.fxml
| |
| | | |-- gui.properties
| |
|-- pom.xml
非常感谢。
【问题讨论】:
-
你在用spring-boot吗?
标签: java spring maven intellij-idea resources