Skip to content

How to pass arguments into a Spring boot run?

To pass arguments when you are running a Spring Boot application you can simply assign your parameters to -Dspring-boot.run.arguments

mvn spring-boot:run -Dspring-boot.run.arguments="--params.filename=employees --params.data=20200302 --params.clientId=asana"

To retrieve these params and use them in your code, declare them in application.properties with dummy values and autowire them with @Value in your actual code.

#application.properties

params.filename=Dummy
params.date=Dummy
params.clientId=Dummy
    @Value("${params.filename}")
    private String fileName;

	@Value("${params.date}")
    private String date;

	@Value("${params.clientId}")
    private String clientId;

	@Value("${params.featureId}")
    private String featureId;

See also  Java String split() Method

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.