如何在命令行中为 Spring Boot 应用程序传递 application.properties? [英] how to pass application.properties in commandLine for a spring boot application?

查看:43
本文介绍了如何在命令行中为 Spring Boot 应用程序传递 application.properties?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 spring boot 应用程序,我想在 start-up<时在 commandLine 中传递 application.properties 文件/代码>.

I have a spring boot application and I want to pass application.properties file in commandLine when I start-up.

即当我运行 mvn spring-boot:run --application.properties

我将在 src/main/resources 中有一个默认的 application.properties.但这仅用于 testing 目的.在 production 运行中,我想在 commandLine.

I will have a default application.properties in src/main/resources. but that is only for testing purposes. In the production run, I would like to pass the property file in commandLine.

我知道传递单个参数,例如

I am aware of passing single arguments such as

mvn spring-boot:run --server.port=9001.

但我有很多这样的属性,如果可能的话,我更愿意传递一个属性文件.

But I have many such properties and would prefer to pass a property file if that is possible.

推荐答案

你可以通过 spring.config.location 属性做到这一点:

You can do that with spring.config.location property:

mvn spring-boot:run -Dspring.config.location=your.properties

这篇关于如何在命令行中为 Spring Boot 应用程序传递 application.properties?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆