As Spring reference https://docs.spring.io/spring/docs/current/spring-framework-reference/integration.html#jmx-notifications-listeners said, I need to set listener mappings by invoking MBeanExporter.setNotificationListenerMappings
method after the notification listener is declared.
When using XML-based config or @Bean annotation config to declare
a MBeanExporter
explicitly, the setNotificationListenerMappings
operation is easily done. As the following code shows:
@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;
}
But when using @EnableMBeanExport, which will automatically define a AnnotationMBeanExporter
, I can't find a way to set listener mappings to MBeanExporter. So, is there a way to set notification listener mappings when I using @EnableMBeanExport
?
Thanks.
The
@EnableMBeanExport
registers in the application context anAnnotationMBeanExporter
bean, so you can inject it into some your configuration and perform such a mapping registration: