gpt4 book ai didi

java - 使用 application.properties 设置 jvm 参数

转载 作者:行者123 更新时间:2023-12-05 03:31:58 25 4
gpt4 key购买 nike

我正在使用带有 docker 等的 spring boot 2.6.2 - 我的应用程序通过 application.properties 读取一些配置,如下所示:

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

foo.bar 绝对按预期工作。但我不确定放.. 是否正确

run.jvmArguments=-Xmx1G -XX:+ExitOnOutOfMemoryError 

.. 也在那里。这行得通吗?

另外 - 我正在使用 spring 中的 DefaultPropertiesPersister 来管理和更改 application.properties 中的一些变量,这非常有用。但出于某种原因,它在其中放置了一些反斜杠,导致:

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

.. 这仍然正确吗?有用吗?

感谢任何帮助或建议:-)

最佳答案

application.properties 中的属性在 JVM 启动之后和应用程序上下文初始化之前加载。

因此它们不可能影响 JVM。

此外,JVM 的应用程序属性和环境属性之间没有任何实际关系。并非每个 spring 应用程序都是为嵌入式服务器加载 JVM 的 spring boot 应用程序。一些 spring 应用程序部署为没有嵌入式服务器的 war ,其中 JVM 已经执行并且它是托管服务器,用于多个应用程序(意味着可能多个 application.properties)。

另请查看 Spring doc

SpringApplication will load properties from application.propertiesfiles in the following locations and add them to the SpringEnvironment

还有 here

All configuration in Spring emanates from the Spring Environmentabstraction. The Environment is sort of like a dictionary - a map withkeys and values. Environment is just an interface through which we canask questions about, you know, the Environment. The abstraction livesin Spring Framework and was introduced in Spring 3, more than a decadeago.

Spring 环境与影响 JVM 的操作系统或系统环境不同。

关于java - 使用 application.properties 设置 jvm 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70541145/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com