[英]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.