【问题标题】:How to set notification listener mappings with Spring JMX integration when I'm using @EnableMBeanExport使用 @EnableMBeanExport 时如何使用 Spring JMX 集成设置通知侦听器映射
【发布时间】:2019-04-24 13:16:38
【问题描述】:

正如 Spring 参考 https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jmx-notifications-listeners 所说,我需要在声明通知侦听器后通过调用 MBeanExporter.setNotificationListenerMappings 方法来设置侦听器映射。

当使用基于 XML 的配置或 @Bean 注解配置来声明时 明确地MBeanExportersetNotificationListenerMappings 操作很容易完成。如下代码所示:

@Bean
public AnnotationMBeanExporter mBeanExporter() {
    Map<String, JmxNotificationListener> mappings = new HashMap<>();
    mappings.put("com.foo.spring-jmx-test:name=JmxService", new JmxNotificationListener());

    AnnotationMBeanExporter exporter = new AnnotationMBeanExporter();
    exporter.setRegistrationPolicy(RegistrationPolicy.IGNORE_EXISTING);
    exporter.setNotificationListenerMappings(mappings);
    return exporter;
}

但是当使用@EnableMBeanExport 时,它会自动定义一个AnnotationMBeanExporter,我找不到将监听器映射设置为MBeanExporter 的方法。那么,当我使用@EnableMBeanExport 时,有没有办法设置通知侦听器映射?

谢谢。

【问题讨论】:

    标签: java spring spring-integration jmx mbeanexporter


    【解决方案1】:

    @EnableMBeanExport 在应用程序上下文中注册一个 AnnotationMBeanExporter bean,因此您可以将其注入到您的配置中并执行这样的映射注册:

    @Autowired
    AnnotationMBeanExporter exporter;
    
    @PostConstruct
    public void init() {
        this.exporter.setNotificationListenerMappings(...);
    }
    

    【讨论】:

      猜你喜欢
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多