Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using application.properties to set jvm arguments

I'm using spring boot 2.6.2 with docker etc. - my app reads some configuration via application.properties which looks like this:

foo.bar=hello
run.jvmArguments=-Xmx1G -XX:+ExitOnOutOfMemoryError 

foo.bar definitely works as expected. But I'm not sure if it's correct to put ..

run.jvmArguments=-Xmx1G -XX:+ExitOnOutOfMemoryError 

.. in there too. Does this work?

Plus - I'm using DefaultPropertiesPersister from spring to manage and change some variables in application.properties which works like a charm. But for some reason it puts some backslashes in there which results in:

run.jvmArguments=-Xmx1G -XX\:+ExitOnOutOfMemoryError

.. is this still correct? Does it work?

Thanks for any help or advice :-)

like image 670
daravetu Avatar asked Nov 16 '25 14:11

daravetu


1 Answers

Properties from application.properties are loaded after the JVM is started and before the application context is initialized.

So there isn't any chance of them affecting the JVM.

Also there is not any real relation between application properties and environment properties for JVM. Not every spring application is a spring boot application that loads a JVM for the embedded Server. Some spring applications are deployed as wars without an embedded server, where the JVM already executes and it is the hosting server, for mutliple applications (meaning probably multiple application.properties).

Also take a look on Spring doc

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment

Also here

All configuration in Spring emanates from the Spring Environment abstraction. The Environment is sort of like a dictionary - a map with keys and values. Environment is just an interface through which we can ask questions about, you know, the Environment. The abstraction lives in Spring Framework and was introduced in Spring 3, more than a decade ago.

Spring environment is not the same as OS or System environment that affects the JVM.

like image 130
Panagiotis Bougioukos Avatar answered Nov 18 '25 04:11

Panagiotis Bougioukos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!