【发布时间】:2021-11-02 23:09:11
【问题描述】:
当我通过命令行运行 jar 时,我想将 SpringBoot 外部的一些配置覆盖到类路径文件中。
类路径 -> application-config.yaml(不是 application.yaml)
server:
port: 8080
servlet:
contextPath: /myapp
test-message: this config no need to export as external config.
外部 -> D:/test/application-config-override.yaml
server:
port: 9090
命令
java -Dspring.config.location=classpath:application-config.yaml,file:///D:/test/application-config-override.yaml -jar myapp.jar
当我运行上面的命令时,应用程序正在运行 8080,contextPath 是“myapp”。我的预期是http://localhost:9090/myapp
但是,如果我将application-config.yaml 的所有相同的配置结构 放入application-config-override.yaml,如下所示
应用程序配置覆盖.yaml
server:
port: 9090
servlet:
contextPath: /yourapp
test-message: this config no need to export as external
应用程序正在运行 9090,contextPath 是“yourapp”。
如何将 SpringBoot 外部的一些配置覆盖到类路径文件中?我正在使用 2.5.4。
我不想将一些不必要的配置导出到外部。我想按顺序调整和覆盖。
【问题讨论】:
-
yml文件名可以改吗?
-
@ray 可以更改。但。对于所有项目+所有 CICD Pipeline 来说,这将是更多的工作量。我们有一百多个微服务。它在 2.1.x 版本上运行良好
-
+ 2.4.0 正在运行
-
你试过我的答案了吗?
标签: java spring spring-boot spring-boot-configuration