Hi Guys,

ich versuche eine Spring-Bean zu einer Mbean zu exportieren (Ich bin recht neu in Spring JMX)

Im Folgenden sind ein paar einfache Codeschnipsel zu sehen

ApplicationContext.xml:

<context:mbean-export/>

Die Spring-Bean welche ich zu einer Mbean exportieren möchte:

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
@Component
@Scope(value = "prototype")
@ManagedResource(objectName = "mymbean:name=AnyMBean", description = "anyMBean", log = true, logFile = "jmx.log", currencyTimeLimit = 15, persistPolicy = "OnUpdate", persistPeriod = 200, persistLocation = "foo", persistName = "status")
public class ExampleClass implements IJmxExampleClassMbean {
 
  
  private int age=28;
  
  @ManagedOperation(description = "Add two numbers")
  @ManagedOperationParameters( { @ManagedOperationParameter(name = "x", description = "The first number"),
      @ManagedOperationParameter(name = "y", description = "The second number") })
  public int add(final int x, final int y) {
    return x + y;
  }
 
  @ManagedAttribute(description = "The Age Attribute", currencyTimeLimit = 15)
  // @ManagedMetric(category = "age-category", displayName = "age", description = "How old are you", metricType = MetricType.GAUGE, unit =
  // "years", currencyTimeLimit = 1000, persistPolicy = "OnUpdate", persistPeriod = 200)
  public int getAge() {
 
    LOG.info("REQUEST: HOW OLD ARE YOU?");
    ArrayList<MBeanServer> findMBeanServer = MBeanServerFactory.findMBeanServer(null);
    Integer mBeanCount = findMBeanServer.get(0).getMBeanCount();
    ObjectInstance objectInstance;
    Object attribute;
 
    try {
      objectInstance = findMBeanServer.get(0).getObjectInstance(ObjectName.getInstance("mymbean:name=GribFileJobMBean"));
      attribute = findMBeanServer.get(0).getAttribute(objectInstance.getObjectName(), "age");
    } catch (InstanceNotFoundException e) {
       e.printStackTrace();
    } catch (MalformedObjectNameException e) {
       e.printStackTrace();
    } catch (NullPointerException e) {
       e.printStackTrace();
    } catch (AttributeNotFoundException e) {
      e.printStackTrace();
    } catch (MBeanException e) {
      e.printStackTrace();
    } catch (ReflectionException e) {
      e.printStackTrace();
    }
    return age;
  }
}

In der JConsole kann ich das Mbean sehen, allerdings schmeisst er bei dem Code:
findMBeanServer.get(0).getAttribute(objectInstance.getObjectName(), "age");

Das schmeisst:
javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for age.


Hyperic sagt das gleiche, wenn ich versuche das age Attribut als Metric darzustellen:
javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for age

Hat jemand Erfahrung damit ?

MfG