【问题标题】:External properties Spring boot外部属性 Spring boot
【发布时间】:2018-02-25 12:41:46
【问题描述】:

我正在尝试让我的 Spring Boot 项目使用在项目之外定义的属性。我已经尝试过文档中描述的步骤,但无法正常工作。

https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

.
+- folder
   +- properties
      +- application.properties
   +- myproject
      +- src

我将它用于 VM 选项:-Dspring.config.location=file:../properties/,但它不起作用。我为spring.config.location 尝试了多个值,但没有成功(我想问题出在此处)。

【问题讨论】:

  • #1。尝试使用 VM 选项上的完整路径,例如:-Dspring.config.location=file:/app/config/properties/。 #2。尝试使用 -- 选项而不是 VM 选项,例如:java -jar myproject.jar --spring.config.location=file:../properties/

标签: java spring-boot properties spring-boot-configuration


【解决方案1】:

假设我有一个连接到 Postgresql 数据库的应用程序。我在我的项目之外有我的数据库连接详细信息,它在一些集中的版本控制系统中。我在我的应用程序中使用bootstrap.properties 文件。我在bootstrap.properties 中进行了配置,以便在应用启动时获取我的数据库连接详细信息。 例如,

postgresql.database.url:${databaseUrl}
postgresql.database.username:${databaseUsername}
postgresql.database.password:${databasePassword}

我将配置键作为值传递给 bootstrap.properties。在应用运行时,它会根据键获取对应的值。

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2019-06-12
    • 2018-06-25
    • 2018-02-21
    • 2015-06-26
    • 2015-08-15
    • 1970-01-01
    • 1970-01-01
    • 2015-05-14
    相关资源
    最近更新 更多