【问题标题】:How to specify external properties files in application.properties in Spring Boot?如何在 Spring Boot 的 application.properties 中指定外部属性文件?
【发布时间】:2019-03-24 19:17:42
【问题描述】:

我有一个项目Projects/MyApp

我有外部属性文件Projects/files

我尝试在application.properties中使用:

spring.config.location=classpath:../files

files 目录包含application-database.properties

我也试过spring.config.location=file:../files/application-database.properties

但它不起作用。怎么了?

【问题讨论】:

  • 据我了解,您在从类路径中选择文件时遇到问题。您无需提及 src/main/resources,因为它是默认的类路径。也使用相对路径而不是绝对路径。
  • 文件应该放在哪里?在与 project.war 相同的目录中?这样的东西合适吗 -> spring.config.additional-localtion:file../../../database.properties ?
  • 如果您将目录结构打包到您的战争中,您无需担心构建目录结构。只需提及放置在类路径中的相对文件名。如果您想外部化设置一些基本目录并从 application.properties 中读取它,然后将所有文件放在该基本目录中。例如 basedirectory = /opt/base.
  • 目录/MyApp 和目录/MyAppFiles。我尝试在 application.properties spring.config.location=classpath:../MyAppFiles/application-database.properties 中使用,它不起作用

标签: java spring spring-boot properties path


【解决方案1】:

据我了解,您可以在 application-database.properties 文件中为您的数据库使用哪些属性,并且您不想在构建后在您的 war 文件中获取凭据。您可以将数据库凭据放入 Idea 环境变量并从 .properties 文件中删除。你怎么看待这件事?

【讨论】:

猜你喜欢
  • 2021-05-17
  • 2020-06-22
  • 2020-03-18
  • 2020-07-30
  • 1970-01-01
  • 2018-02-21
  • 2015-06-26
  • 2020-05-03
  • 2014-08-09
相关资源
最近更新 更多