【问题标题】:spring boot jar not picking profile specific properties outside jarspring boot jar 没有在 jar 之外选择配置文件特定属性
【发布时间】:2018-04-22 00:55:00
【问题描述】:

我在目录结构中有一个 spring boot jar(name : myjar)

D:/hello/myjar

fat jar 在 src/main/resources 中包含配置文件特定的 application.properties,例如应用程序-local.properties

我想用jar外的application-local.properties覆盖jar内的application-local.properties中定义的属性

因此我创建了 application-local.properties 并将其保存在与 jar 相同的文件夹中,即 D:/hello

但是,当我使用以下命令运行我的 jar 时:

java -jar -Dspring.profiles.active=local D:/hello/myjar.jar

它仍然会选择 jar 中的属性。我错过了什么吗?

【问题讨论】:

  • 你的命令看起来不错,试试java -jar D:\hello\myjar.jar --spring.profiles.active=local --spring.config.location=D:\hello
  • 不走运,它仍然会选择 fat jar 中的 application-local.properties。肯定有一些缺失的链接。我希望 jar 选择 jar 之外的属性文件。

标签: spring-boot


【解决方案1】:

尝试在 -jar 之前使用 -D

java -Dspring.profiles.active=local -jar  D:/hello/myjar.jar

让我们看看https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config

【讨论】:

  • 谢谢!但我得到了答案。请检查我的答案。
【解决方案2】:

我认为从命令提示符运行 jar 的位置更重要。

如果我从 jar 所在的文件夹运行 jar,它会选择 jar 外部存在的配置文件特定文件。

【讨论】:

    猜你喜欢
    • 2018-11-11
    • 2019-06-12
    • 2017-06-21
    • 2020-09-07
    • 2017-06-04
    • 2012-08-26
    • 2016-04-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多