在spring中替换xml本身的@managed操作

时间:2014-01-17 06:11:54

标签: spring jmx spring-jmx

我使用的是Spring 2.5版的JMX,我使用的是JMX 如下图所示..

@ManagedOperation(description = "Mark the Entry corresponding ABC flow")
@ManagedOperationParameters(value = {
        @ManagedOperationParameter(name = "def", description = "Ids of the entries that needs to be STOP"),
        @ManagedOperationParameter(name = "Comments", description = "Note on why these entries are being marked as stop") })
public void abcstop(String def, String gtr){
    StringBuffer gfhtrPresent= jmxService.abcd(Ids, comments);
    if(idsNotPresent.length()>0) 
        throw new IOARuntimeException("<font color=red><b>No data found for the following id/id's </b></font>"+idsNotPresent);
}

现在我想删除@Managedoperation annaotation并希望用XML配置它,请告诉我如何配置@Managedoperation,因为我想从xml本身运行相同的功能,请指教。 请各位建议,因为我被困住任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您可以使用XML导出MBean - 请参阅documentation。但是,AFAIK,标准组件无法添加这样的描述。

您必须实现自己的MBeanInfoAssembler(或其中一个标准的子类)。

编辑:

例如,AbstractReflectiveMBeanInfoAssembler通过调用getOperationDescription()获取createModelMBeanOperationInfo中的操作说明。默认情况下,这只返回方法名称。 MetadataMBeanInfoAssembler(用于注释)会覆盖此方法以从注释中获取描述。

因此,您可以继承MethodNameBasedMBeanInfoAssembler并实现getOperationDescription()方法以从任何您想要的地方获取描述(可能是XML中的另一个属性)。

类似地,操作参数描述在getOperationParameters()中设置,因此您将覆盖它以构建它们。请参阅MetadataMBeanInfoAssembler,了解他是如何从注释中完成的。