为什么 JBoss JMX 控制台不显示 Spring 定义的 MBean 的描述?

发布于 2024-09-24 14:36:27 字数 1140 浏览 0 评论 0原文

我有一个使用 Spring 注释通过 JMX 公开的 Spring bean,但参数名称保持空白,并且操作和参数描述不显示。是否可以在不借助繁琐的 XML 定义文件的情况下解决此问题?

我是在博客文章之后实现的。这是我的简化代码:

import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource(objectName="group:name=foo", description="Does a lot of fooing")
public class Foo {
    @ManagedOperation(description="Changes the period of the given task and applies it immediately if the task is enabled.")
    @ManagedOperationParameters({
        @ManagedOperationParameter(name="index", description="the 0-based index of the fizzle"),
        @ManagedOperationParameter(name="baz", description="the baz value to set on the fizzle")
    })
    public void changeFizzle(int index, long baz) {
        // impl
    }
}

相关的 spring 应用程序上下文定义是从上面链接的博客文章中逐字复制的。

I have a Spring bean that is exposed via JMX using Spring annotations, but the parameter names remain blank and the operation and parameter descriptions don't show up. Can this be fixed without resorting to tedious XML definition files?

I implemented this closely following a blog post. Here's my simplified code:

import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource(objectName="group:name=foo", description="Does a lot of fooing")
public class Foo {
    @ManagedOperation(description="Changes the period of the given task and applies it immediately if the task is enabled.")
    @ManagedOperationParameters({
        @ManagedOperationParameter(name="index", description="the 0-based index of the fizzle"),
        @ManagedOperationParameter(name="baz", description="the baz value to set on the fizzle")
    })
    public void changeFizzle(int index, long baz) {
        // impl
    }
}

The relevant spring application context definition is copied verbatim from the blog post linked above.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦归所梦 2024-10-01 14:36:27

您需要为 MBeanExporter 定义正确的 MetadataMBeanInfoAssembler,如下所示:

<property name="assembler">
  <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource">
      <bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
    </property>
  </bean>
</property>

You need to define the correct MetadataMBeanInfoAssembler like this for the MBeanExporter:

<property name="assembler">
  <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
    <property name="attributeSource">
      <bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
    </property>
  </bean>
</property>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文