簡體   English   中英

如何在命令行中為 Spring Boot 應用程序傳遞 application.properties?

[英]how to pass application.properties in commandLine for a spring boot application?

我有一個spring boot應用程序,我想通過application.properties文件中的commandLine ,當我start-up

即當我運行mvn spring-boot:run --application.properties

我將在src/main/resources有一個默認的 application.properties 。 但這僅用於testing目的。 production運行中,我想在命令行中傳遞property file commandLine.

我知道傳遞單個參數,例如

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

但是我有很多這樣的屬性,如果可能的話,我更願意傳遞一個屬性文件。

你可以用spring.config.location屬性做到這spring.config.location

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

如果有人覺得它對我有用。 如果您想在使用 maven spring boot run 命令時將單個應用程序屬性作為參數傳遞,您可以使用參數 spring-boot.run.jvmArguments。

例如:

mvn spring-boot:run -Dspring-boot.run.jvmArguments='
-Dspring.datasource.url=jdbc:postgresql://localhost:5432/mydb 
-Dspring.datasource.username=admin 
-Dspring.datasource.password=admin'

使用上述命令,我正在設置(覆蓋)application.properties 文件中的以下屬性。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM