Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass JVM arguments in SpringBOOT

I would like to pass JVM arguments in the main spring boot class where we will be starting the spring boot application.

Could you please share how to set JVM arguments in spring boot application?

I tried the below options and there is no luck

System.setProperty("http.proxyHost", "X.X.X.X");
System.setProperty("http.proxyPort", "8080");

or you can use this for spring boot

bootRun {
    systemProperties "property1": "value1", "property2": "value2"
}
like image 609
SpringForLiving Avatar asked Nov 10 '15 16:11

SpringForLiving


People also ask

What is JVM argument?

JVM arguments are flags that are passed to the Java Virtual Machine at the time the application is launched. On Linux or Mac machines, they can be provided through the JAVA_OPTS setting in the whd.conf file.

What is difference between CommandLineRunner and ApplicationRunner?

ApplicationRunner takes ApplicationArgument which has convenient methods like getOptionNames(), getOptionValues() and getSourceArgs(). CommandLineRunner run() will get execute, just after applicationcontext is created and before spring boot application starts up.


1 Answers

Add JVM arguments with -DargumentName i.e.

-DargumentName="value1"

Then in your spring application, you can retrieve the value by doing:

@Value("${argumentName}")
private String myVariable

Hope this helps!

like image 172
Kabir Avatar answered Oct 21 '22 01:10

Kabir