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"
}
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.
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.
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!
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