Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 如何在spring引导应用程序的命令行中传递application.properties?_Spring Boot_Spring 4 - Fatal编程技术网

Spring boot 如何在spring引导应用程序的命令行中传递application.properties?

Spring boot 如何在spring引导应用程序的命令行中传递application.properties?,spring-boot,spring-4,Spring Boot,Spring 4,我有一个spring boot应用程序,我想在启动时传递命令行中的应用程序.properties文件 i、 当我运行mvn spring boot:run--application.properties时 我将在src/main/resources中有一个默认的application.properties。但这仅用于测试目的。在生产运行中,我想在命令行中传递属性文件。 我知道传递单个参数,例如 mvn spring引导:运行--server.port=9001 但是我有很多这样的属性,如果可能的

我有一个
spring boot
应用程序,我想在
启动时传递
命令行中的
应用程序.properties
文件

i、 当我运行mvn spring boot:run--application.properties时

我将在
src/main/resources
中有一个默认的application.properties。但这仅用于测试目的。在
生产
运行中,我想在
命令行中传递
属性文件

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

mvn spring引导:运行--server.port=9001


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

您可以使用
spring.config.location
属性:

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

mvn spring boot:run-Dspring boot.run.arguments=--spring.config.location=classpath:/application local.properties

以防有人发现它对我很有用。如果在使用maven-spring-boot-run命令时希望将单个应用程序属性作为参数传入,则可以使用参数spring-boot.run.JVM arguments

例如:

使用上述命令,我正在设置(覆盖)application.properties文件中的以下属性

spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=admin
spring.datasource.password=admin
spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=admin
spring.datasource.password=admin