本文介绍了如何设置嵌入式tomcat jvmroute的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我需要设置 Spring Boot 的嵌入式 tomcat 使用的 jvmRoute,但看起来我能做到这一点的唯一简单方法是传入一个 jvm 参数,例如:-DjvmRoute=myroute

I need to set the jvmRoute used by Spring Boot's embedded tomcat, but it looks like the only easy way I can do this is by passing in a jvm argument, e.g: -DjvmRoute=myroute

我宁愿在 application.properties 中设置此属性.jvm 参数是我唯一的选择,还是我遗漏了什么?

I'd rather set this property in application.properties. Is the jvm argument my only option, or am I missing something?

推荐答案

这是我想出的办法来解决我的问题.由于 org.apache.catalina.core.StandardEngine 基于 System 属性设置 jvmRoute,我只需从 application.properties 获取我自己的 tomcat.jvmroute 属性,并将其设置为 @Configuration 文件中的 System 属性:

Here's what I came up with to solve my problem. Since the org.apache.catalina.core.StandardEngine sets the jvmRoute based on a System property, I simply get my own tomcat.jvmroute property from application.properties, and set it as a System property in a @Configuration file:

@Configuration
public class TomcatConfig {
    @Value("${tomcat.jvmroute}")
    private String jvmRoute;

    @PostConstruct
    public void setJvmRoute() {
        // embedded tomcat uses this property to set the jvmRoute
        System.setProperty("jvmRoute", jvmRoute);
    }
}

这篇关于如何设置嵌入式tomcat jvmroute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 22:17