Ramon Li
Ramon Li

Reputation: 21

No JMX mbeans found of springboot2's embeded tomcat

We have upgraded our system to springboot2(springboot-2.2.2+ springCloud-Hoxton.RELEASE), and found that there were no any Tomcat related JMX mbeans. Below is what I got when connect to my local application by jvisualvm:

springboot2-v2.2.2

springboot2-v2.2.2+jmx-enabled

Also I implemented a springboot2(v2.1.1) demo, it was ok, tomcat‘s JMX mbeans works well. The strange thing is there are 2 tomcat.

springboot-v2.1.1

springboot-v1.5.3

As I have implemented a Endpoint to monitor the thread pool of tomcat, which completely depends on JMX of tomcat, now it doesn't work any more. Please help, is there any way to enable the JMX of tomcat with springboot-v2.2.2?

Upvotes: 2

Views: 1471

Answers (3)

bmck
bmck

Reputation: 229

You can use the following vm argument for the Mbean not appearing up issue.

-Dspring.jmx.enabled=true

Upvotes: 1

LE GALL Benoît
LE GALL Benoît

Reputation: 7578

By now, you can simply use

server:
  tomcat:
    mbeanregistry:
      enabled: true

so as a better spring-boot way of doing it

Upvotes: 4

cps
cps

Reputation: 41

To enable Tomcat JMX in springboot 2.2 following tomcat customizer must be configured:

@Bean
public WebServerFactoryCustomizer<TomcatServletWebServerFactory> activateTomcatMBeanServer() {

    return (factory) -> {
        factory.setDisableMBeanRegistry(false);
    };
}

This has been introduced with SpringBoot Issue 16498 and Version 2.2.0.M4. Spring Boot utilizes a new feature of Tomcat 9.0.20 which allows to disable Tomcat’s MBeanServer (org.apache.tomcat.util.modeler.Registry. disableRegistry() - Tomcat also uses this switch when Graal is present). The corresponding Tomcat issue is Tomcat Issue 63361.

Upvotes: 4

Related Questions