简体   繁体   English

使用 application.properties 设置 jvm arguments

[英]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:我正在使用 spring 启动 2.6.2 和 docker 等 - 我的应用程序通过application.properties读取一些配置,如下所示:

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

foo.bar definitely works as expected. foo.bar 绝对按预期工作。 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.另外 - 我正在使用 spring 中的DefaultPropertiesPersister来管理和更改application.properties中的一些变量,这就像一个魅力。 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:-)感谢您的任何帮助或建议:-)

Properties from application.properties are loaded after the JVM is started and before the application context is initialized. application.properties中的属性在 JVM 启动之后和应用程序上下文初始化之前加载。

So there isn't any chance of them affecting the JVM.所以它们不可能影响 JVM。

Also there is not any real relation between application properties and environment properties for JVM. JVM 的应用程序属性和环境属性之间也没有任何实际关系。 Not every spring application is a spring boot application that loads a JVM for the embedded Server.并非每个 spring 应用程序都是为嵌入式服务器加载 JVM 的 spring 引导应用程序。 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 ).一些 spring 应用程序部署为没有嵌入式服务器的战争,其中 JVM 已经执行并且它是托管服务器,用于多个应用程序(意味着可能是多个application.properties )。

Also take a look on Spring doc另请查看Spring 文档

SpringApplication will load properties from application.properties files in the following locations and add them to the Spring Environment SpringApplication 将从以下位置的 application.properties 文件中加载属性并将其添加到Spring环境

Also here也在这里

All configuration in Spring emanates from the Spring Environment abstraction. Spring 中的所有配置都源自 Spring 环境抽象。 The Environment is sort of like a dictionary - a map with keys and values.环境有点像字典 - 带有键和值的 map。 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 框架中,并在十多年前的 Spring 3 中引入

Spring environment is not the same as OS or System environment that affects the JVM. Spring 环境与影响 JVM 的操作系统或系统环境不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM