[英]How do I set the JVM properties of an executable Spring Boot jarfile?
As a follow-up question to How do I build a Spring Boot jarfile that systemd can execute directly as a service? 作为如何构建Spring Boot jarfile的后续问题,systemd可直接作为服务执行? , how do I set the JVM properties of an executable Spring Boot jarfile?
,如何设置可执行Spring Boot jarfile的JVM属性? For example, how do I set the maximum heap size (ie
-Xmx2048m
)? 例如,如何设置最大堆大小(即
-Xmx2048m
)?
Place your-app.conf
next to your-app.jar
with content 将内容
your-app.conf
your-app.jar
旁边
JAVA_OPTS=-Xmx2048M
Refer to deployment script customization guide or launch.script for details. 有关详细信息,请参考部署脚本定制指南或launch.script 。
This is not a direct answer to your question, but a way how to work around. 这不是您问题的直接答案,而是解决方法。
I have never opted for an executable jar since I believe it's more flexible to set the parameters from outside at app startup. 我从未选择使用可执行jar,因为我认为在应用程序启动时从外部设置参数会更加灵活。
This is how to set JVM system properties and application properties via command line: 这是通过命令行设置JVM系统属性和应用程序属性的方法:
java -Xmx2048m -jar application.jar --paramname="paramvalue"
You can then get the parameter paramname
in a Spring Bean or Service like this: 然后,您可以像这样在Spring Bean或Service中获取参数
paramname
:
@Value("${paramname}")
private String paramname;
You can read more about that topic here: 您可以在此处阅读有关该主题的更多信息:
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
Edit 编辑
Take a look at this answer which seems to be what you're looking for: 看一下这个答案,这似乎是您想要的:
https://stackoverflow.com/a/33856394/272180 https://stackoverflow.com/a/33856394/272180
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.