Java 以编程方式将DirectChannelMetrics注册为JMX Bean

Java 以编程方式将DirectChannelMetrics注册为JMX Bean,java,spring,inversion-of-control,spring-integration,jmx,Java,Spring,Inversion Of Control,Spring Integration,Jmx,我有一个Spring集成应用程序,其中有几个FileTailingMessageProducers和DirectMessageChannels是通过编程方式创建的,即不是通过XML配置,而是在ApplicationListener中创建的。现在,我想使用JMX监视消息通道。我想我必须使用integrationMBeanExporter添加它们 这就是我所尝试的: DirectChannelMetrics directChannelMetrics = new DirectChannelMetric

我有一个Spring集成应用程序,其中有几个
FileTailingMessageProducer
s和
DirectMessageChannel
s是通过编程方式创建的,即不是通过XML配置,而是在
ApplicationListener
中创建的。现在,我想使用JMX监视消息通道。我想我必须使用integrationMBeanExporter添加它们

这就是我所尝试的:

DirectChannelMetrics directChannelMetrics = new DirectChannelMetrics(tailedLines, "tailedLines");
integrationMBeanExporter.getServer().registerMBean(directChannelMetrics, new ObjectName("d:foo=foo"));
但我得到了以下例外:

javax.management.NotCompliantMBeanException: MBean class org.springframework.integration.monitor.DirectChannelMetrics does not implement DynamicMBean, and neither follows the Standard MBean conventions
令我惊讶的是,DirectChannelMetrics没有满足JMX的要求,因为当我使用jvisualvm查看我的应用程序时,我可以看到这种类型的其他bean注册没有问题


有什么想法吗?

从一个侧面
MBeanExporter
在这个问题上:

return new StandardMBean(bean, ((Class<Object>) ifc));
返回新的标准MBean(bean,((类)ifc));
在将bean注册为
MBean
之前

从另一个角度看,我觉得你的逻辑有点异味。在运行时创建
MessageChannel
s看起来异常。特别是那些用于JMX导出的


我同意动态
FileTailingMessageProducer
s,但在我看来,我们可以通过重构预定义通道的逻辑来避免动态通道。

您可以利用Spring的
MBeanExport.registerManagedResource(directChannelMetrics,新对象名(“d:foo=foo”)
。Spring将为
DirectChannelMetric
类的实例生成一个管理接口。但是
DirectChannelMetric
类需要实现
Mbean
/
MXBean
接口,或者满足当前
MBeanInfoAssembler
的期望(如果是
MetadataMBeanInfoAssembler
则标记有
@ManagedResource
注释,如果是
InterfaceBasedMBeanfoAssembler
则实现指定接口之一)