3

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 :-)

daravetu
  • 113
  • 2
  • 6
  • 1
    Does it work? Does your JVM end up with the arguments you want? – tgdavies Dec 31 '21 at 10:15
  • That is my question. I'm not sure... I tried to check it but I don't know how. This e.g. https://alvinalexander.com/java/how-see-jvm-parameters-arguments-from-running-java-application/ gives me just an empty list. – daravetu Dec 31 '21 at 10:28
  • 1
    Why not use `jps`: https://stackoverflow.com/a/7612674/8961170 – AlirezaAsadi Dec 31 '21 at 10:51
  • 2
    Does this answer your question? [How to add JVM options to program started by mvn spring-boot:run](https://stackoverflow.com/questions/44735189/how-to-add-jvm-options-to-program-started-by-mvn-spring-bootrun) – Joe Dec 31 '21 at 11:42

1 Answers1

3

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.

Panagiotis Bougioukos
  • 15,955
  • 2
  • 30
  • 47