【问题标题】:how to tell intellij to use application.properties outside resources folder?如何告诉 Intellij 在资源文件夹之外使用 application.properties?
【发布时间】:2018-11-17 13:40:21
【问题描述】:

我的 Spring Boot 项目正在使用 gradle 生成的 application.properties 文件,该文件位于 build 目录下,而不是典型的资源目录中。
如何告诉 Intellij 将生成的 application.properties 文件拉入 build/resources/main 下并忽略 src/main/resources 下的那个?谢谢。

【问题讨论】:

标签: intellij-idea


【解决方案1】:

我很抱歉没有给出这个答案作为评论,但我还没有必要的声誉来发表评论。

您正在尝试做的更多是与 Spring Boot 而不是 Intellij 相关(添加 Spring Boot 标签将在未来有所帮助)。

This Stack Overflow post 可能会帮助您走上正确的道路。

基本上你需要将你的build/resources/main/application.properties 文件添加到你的类路径中。一旦进入您的类路径,Spring 将能够看到并阅读它。

但是,这仍然会给您留下两个可供 Spring 使用的 application.properties 文件。我不确定它会选择哪个,或者它是否会同时阅读。

您可能想研究使用 Spring Profiles 来告诉 Spring 要读取哪个属性文件。可以在 google 上找到有关带有配置文件的属性文件的更多信息。我还发现 this 的帖子很有帮助。

如果这些都不是您想要的,另一个(不太理想和肮脏的)选项是将您生成的文件移动到您的src/main 目录下。然后 Spring 会自动看到它。

【讨论】:

  • 谢谢!加载中...很好的回复。
猜你喜欢
  • 2019-09-07
  • 2023-04-10
  • 2015-01-21
  • 1970-01-01
  • 2012-09-01
  • 2015-10-20
  • 2013-03-10
  • 1970-01-01
  • 2017-02-06
相关资源
最近更新 更多