簡體   English   中英

Spring 引導:application.properties 的路徑

[英]Spring boot: path to application.properties

假設我想從 /tmp/application.properties 加載 application.properties。 當我通常執行應用程序時,我該怎么做

mvn spring-boot:run

我閱讀了所有文檔和 stackoverflow 帖子,但無法正常工作。 通常我會發現:

java -jar -Dspring.config.location=<path-to-file> myBootProject.jar

但這在通過 mvn-spring-boot:run 執行時似乎不起作用。 我也試過沒有成功:

mvn spring-boot:run -Drun.jvmArguments="-Dspring.config.location=/tmp/application.properties"

spring-boot:run目標有一個完全用於該目的的可選參數: spring-boot.run.arguments

在您的情況下,您要配置的屬性是--spring.config.location=<path-to-file> 因此,您可以使用以下命令:

mvn spring-boot:run -Dspring-boot.run.arguments=--spring.config.location=<path-to-file>

來源: https://docs.spring.io/spring-boot/docs/current/maven-plugin/run-mojo.html#arguments

我所做的:

java -jar example.jar --spring.config.location=<my_location>

按預期工作。 你試過這個嗎?

暫無
暫無

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

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