简体   繁体   English

Spring Boot @ManagedResource 组件在 Docker 中启动时在 VisualVM 中不可见,但在本地工作

[英]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:我有一个 Spring 组件:

@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:当我在本地启动应用程序(使用 IDE)并使用VisualVM通过 JMX 连接时,我可以查看和管理 bean: 在此处输入图像描述

But, when I launch the app in a container (locally as well), I do not see the bean.但是,当我在容器中(也在本地)启动应用程序时,我看不到 bean。 Moreover, I do not see any Spring related managing facilities as well:此外,我也没有看到任何与 Spring 相关的管理设施:

在此处输入图像描述

Here is my JMX opts that I pass into Dockerfile entrypoint when launchign the JAR file within:这是我在启动 JAR 文件时传入 Dockerfile 入口点的 JMX 选项:


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. DOCKER_HOST_IP=127.0.0.1显然在本地启动时。

So issue, that MBeans are not recognized in a container at all.所以问题是,容器中根本无法识别 MBean。

Any idea folks?大家有什么想法吗? Thanks谢谢

Figured out that the solution is very simple: add to your JMX_OPT the following property:发现解决方案非常简单:将以下属性添加到您的 JMX_OPT:

-Dspring.jmx.enabled=true

details here详情在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring Boot自动连线@ManagedResource - Spring Boot autowire @ManagedResource Spring Boot网站在本地工作,但无法远程访问 - Spring boot website works locally but not accessible remotely Spring Boot Service在本地工作,但不能在远程工作 - Spring Boot Service works locally but not remotely Java VisualVM挂起连接到从eclipse启动的本地进程 - Java VisualVM hangs connecting to locally process launched from eclipse 当本地一切正常时,Spring Boot Security 会导致应用程序在部署到 GAE 时关闭 - Spring Boot Security causes application to shutdown when deployed to GAE when locally everything works fine 使用 Spring 将图像上传到 Google Cloud 存储启动在本地工作,但在部署时它不起作用 - Image upload to Google Cloud storage with Spring Boot works locally but when deploy it doesn't work 使用Docker时的Spring Boot外部配置 - Spring Boot External Configuration when using Docker Spring 引导在 aws fargate 上运行但不在本地时被 cors 阻止 - Spring boot blocked by cors when running on aws fargate but not locally spring 引导组件 bean 验证 @Positive 不起作用但 @NotNull 工作正常 - spring boot component bean validation @Positive not working but @NotNull works fine 单元测试时Spring Boot删除@Component - Spring Boot remove @Component when unit testing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM