Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 705
brain storm Avatar asked Aug 04 '15 21:08

brain storm


3 Answers

You can do that with spring.config.location property:

mvn spring-boot:run -Dspring.config.location=your.properties
like image 133
mzc Avatar answered Oct 17 '22 17:10

mzc


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
like image 32
Dehan Avatar answered Oct 17 '22 19:10

Dehan


mvn spring-boot:run -Dspring-boot.run.arguments=--spring.config.location=classpath:/application-local.properties
like image 3
Sarath Sasikumar Avatar answered Oct 17 '22 17:10

Sarath Sasikumar