java - 特定模块的 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 配置,但不确定是否:
必须更改方法并将@EnableMBeanExport 放置一次,在主配置中的某个位置
必须创建一个新注释,这将改变默认流程
将 sth 添加到注释以在特定模块上激活它
解决方案
请参阅 .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。
请参阅控制注册行为。
推荐阅读
- nginx - nginx如何配置处理过多的请求?
- jenkins - Jenkins Job DSL 使用配置作为 Cod 插件创建种子作业
- oop - 文件编写器函数应该放在不属于逻辑的代码中的什么位置?
- syntax - 如何在 Sublime Text 中为法语算法设置颜色
- java - Kinesis Aync 客户端 2.x 给出 Http2ConnectionTerminatingException
- javascript - 根据输入值动态包含刀片模板
- ios - 如何在 UIKit UiSlider 中为自定义 thumbImage 添加阴影?
- c++ - Visual Studio C++ - 模板类 LNK2019 错误
- php - Pico CMS - 标签插件设置和分页
- r - 如何将一个字符串分成多个变量