вы должны вернуть CompositeData или TabularDataSupport в качестве типа возврата.Следующий код демонстрирует оба и должен работать для вас.Дайте мне знать, если у вас возникнут какие-либо проблемы.
package com.example.demo;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;
import javax.management.openmbean.*;
@Component
@ManagedResource(objectName="com.example.demo.jmx:name=ServerManager",
description="Server manager.")
public class SampleOperation {
private static final String[] itemNames = new String[] { "name", "age" };
private static final String[] itemDescription = new String[] { "Your name", "Your age" };
private static final OpenType<?>[] itemTypes = new OpenType[] {
SimpleType.STRING,
SimpleType.INTEGER
};
public static final String IAC_CHARGE_CODE = "IacChargeCode";
public static final String BANK_CHARGE_CODE = "BankChargeCode";
public static final String TOP_UP_PROVIDER = "TopUpProvider";
public static final String[] rowItemNames = new String[] { IAC_CHARGE_CODE, BANK_CHARGE_CODE, TOP_UP_PROVIDER };
public static final String[] rowItemDescriptions = new String[] {
"Iac charge code",
"Bank charge code",
"Top up provider"
};
@ManagedOperation(description="Get the complex object.")
@ManagedOperationParameters({
@ManagedOperationParameter(name="name", description= "Your name."),
@ManagedOperationParameter(name="age", description= "Your age.")})
public CompositeData simpleData(String name, int age) throws Exception {
CompositeType compositeType = new CompositeType(
"NameAndAge",
"name and age",
itemNames, itemDescription, itemTypes);
CompositeData data = new CompositeDataSupport(compositeType, itemNames, new Object[] {
name, age
});
return data;
}
@ManagedOperation(description="Retrieve recodes from DB.")
public TabularDataSupport tabular() throws OpenDataException {
OpenType<?>[] rowItemTypes = new OpenType[]{
SimpleType.STRING, SimpleType.STRING, SimpleType.STRING
};
CompositeType compositeRowType = new CompositeType(
"chargeRow",
"some row",
rowItemNames,
rowItemDescriptions,
rowItemTypes);
TabularType tabularType = new TabularType(
"charge table",
"Sample table of charge",
compositeRowType,
rowItemNames);
TabularDataSupport rows = new TabularDataSupport(tabularType);
rows.putAll(new CompositeData[]{
new CompositeDataSupport(compositeRowType, rowItemNames, new Object[]{
"charge code #1", "bank charge code #1", "Top up #1"
}),
new CompositeDataSupport(compositeRowType, rowItemNames, new Object[]{
"charge code #2", "bank charge code #2", "Top up #2"
}),
new CompositeDataSupport(compositeRowType, rowItemNames, new Object[]{
"charge code #3", "bank charge code #3", "Top up #3"
}),
});
return rows;
}
}