javadockerjmxspring-jmx

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: enter image description here

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:

enter image description here

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


Solution

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

    -Dspring.jmx.enabled=true

    details here