简体   繁体   中英

Spring Boot @ManagedResource component is not visible in VisualVM when launched in Docker but works locally

The issue is very straightforward to reproduce. I have a Spring component:

@Component
@ManagedResource
public class EncryptionUtil {

   ...

    @ManagedOperation
    public String encrypt(String plain) {
       ...
    }

    @ManagedOperation
    public String decrypt(String encrypted) {
       ...
    }
}

When I launch the app locally (using IDE) and connecting over JMX using VisualVM I can see and manage the bean: 在此处输入图像描述

But, when I launch the app in a container (locally as well), I do not see the bean. Moreover, I do not see any Spring related managing facilities as well:

在此处输入图像描述

Here is my JMX opts that I pass into Dockerfile entrypoint when launchign the JAR file within:


JMX_OPTS="-Dcom.sun.management.jmxremote=true\
          -Dcom.sun.management.jmxremote.local.only=false\
          -Dcom.sun.management.jmxremote.authenticate=false\
          -Dcom.sun.management.jmxremote.ssl=false\
          -Djava.rmi.server.hostname=$DOCKER_HOST_IP\
          -Dserver.port=$PORT\
          -Dcom.sun.management.jmxremote.port=9090\
          -Dcom.sun.management.jmxremote.rmi.port=9090"

DOCKER_HOST_IP=127.0.0.1 when launch locally obviously.

So issue, that MBeans are not recognized in a container at all.

Any idea folks? Thanks

Figured out that the solution is very simple: add to your JMX_OPT the following property:

-Dspring.jmx.enabled=true

details here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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