首页 > 解决方案 > 特定模块的 JMX spring 配置

问题描述

目前,我们有一个单体应用程序,其中所有 mbean 都在一个地方定义。将来它们将被迁移并放置在专用模块中,每个模块都将具有其弹簧上下文定义。

发现 @EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING) 对于从原始解决方案迁移到新方法很有用。我的春季版本是 5.2.4

我希望控制 mbeans 导出,但从 javadoc (AnnotationMBeanExporter) 中注意到,默认情况下使用此注释从 spring 上下文中导出所有 mbeans。这意味着来自模块 A 的 jmx 配置将发布来自其他模块 B 或 C 的 mbean,甚至来自 3rd 方库的 mbean 也将可用。

我计划仅在想要公开 mbean 的特定模块上设置 JMX 配置,但不确定是否:

标签: javaspringspring-jmxjmx-exporter

解决方案


请参阅 .java 文档@EnableMBeanExport

 * <p>The resulting {@link org.springframework.jmx.export.MBeanExporter MBeanExporter}
 * bean is defined under the name "mbeanExporter". Alternatively, consider defining a
 * custom {@link AnnotationMBeanExporter} bean explicitly.
 *

因此,只需将其声明AnnotationMBeanExporter为 a@Bean并将其配置为仅注册您需要的 bean。

请参阅控制注册行为


推荐阅读