首页 > 解决方案 > 如何将 SpringBoot JMX bean 与 Jolokia 连接?

问题描述

我在 SpringBoot 应用程序中使用 @EnableMBeanExport 使我的带有 @ManagedResource 的 bean 可用于 JMX 服务器。这在 VisualVM 的简单本地进程中运行良好。

我现在正在尝试将 Jolokia 添加到组合中,因此我可以使用 REST 服务远程引用这些 bean,而不是设置远程 RMI 连接,这很烦人。

https://jolokia.org/reference/html/jmx.html上的 Jolokia 文档页面说要使用以下内容:

MBeanServer jolokiaServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer();

但是,Jolokia 中似乎没有“JolokiaMBeanServerUtil”类。

更新

好的,我在类中找到了工件,但解决方案似乎并不像仅声明具有此值的 bean 那样简单。当我尝试使用 jolokia url 调用 jmx 方法时,出现如下异常:

java.lang.IllegalArgumentException: Invalid object name. Key properties cannot be empty
    at org.jolokia.request.JmxRequestFactory.createGetRequest(JmxRequestFactory.java:99)
    at org.jolokia.http.HttpRequestHandler.handleGetRequest(HttpRequestHandler.java:79)
    at org.jolokia.http.AgentServlet$4.handleRequest(AgentServlet.java:470)

标签: javaspring-bootjmxjolokia

解决方案


推荐阅读