I have a spring boot
application and I want to pass application.properties
file in commandLine
when I start-up
.
i.e when I run mvn spring-boot:run --application.properties
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.
You can do that with spring.config.location
property:
mvn spring-boot:run -Dspring.config.location=your.properties
In case if anyone finds it useful as it was for me. If you want to pass in individual application properties as parameters when using the maven spring boot run command you can use the argument spring-boot.run.jvmArguments.
Eg:
mvn spring-boot:run -Dspring-boot.run.jvmArguments='
-Dspring.datasource.url=jdbc:postgresql://localhost:5432/mydb
-Dspring.datasource.username=admin
-Dspring.datasource.password=admin'
With the above command I am setting (overriding) the following properties which were in the application.properties file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With