2017-03-23 6 views
0

私は、Spring JMXアノテーションを駆動して(xml:Dを持たない)いくつかの情報をエクスポートしようとしています。 String型とInteger型をエクスポートすることに成功しましたが、作成したクラスのオブジェクトをエクスポートできませんでした。Spring JMXアノテーションでオブジェクトをエクスポートする

これは私の@Configurationクラスです。

@Configuration 
@EnableMBeanExport 
@ComponentScan({"my.packages"}) 
public class AppManager { 

    public static void main(String[] args) { 

     AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); 
     context.register(AppManager.class); 
     context.refresh(); 


     try { 
      TimeUnit.MINUTES.sleep(30); 
     } catch (InterruptedException e) { 
      e.printStackTrace(); 
     } 
    } 

    @Bean(name = "jmxExporter") 
    public Exporter jmxExporter() { 
     return new Exporter(); 
    } 
} 

これは私が得たいと思ういくつかのクラスです。

public class MyClass implements Serializable { 

    private int param1; 
    private int param2; 
    private int param3; 

    public MyClass() { 
     // calculate all params 
    } 

    public int getParam1() { 
     return this.param1; 
    } 

    public int getParam2() { 
     return this.param2; 
    } 

    public int getParam3() { 
     return this.param3; 
    } 

} 

これは、その属性をエクスポートするクラスです。

私は個別にエクスポートすることができないリアルタイム情報があるため、毎回MyClassオブジェクトを作成する必要があります。

JConsoleでは、属性の値は「使用不可」です。

私はJMXにはかなり新しく、明らかに何か不足しています。

ありがとうございました!

答えて

0

CompositeDataを返すことで解決しました。

@ManagedAttribute 
public CompositeData getMyClass() { 
    return createCompositeDataForMyClass(); 
} 

私はそれに対してCompositeDataSupportを構築しました。

return new CompositeDataSupport(compositeType, itemNames, itemValues); 

compositeTypeがCompositeTypeの場合、itemNamesはString []、itemValuesはObject []です。 CompositeTypeは型名この

new CompositeType(typeName, typeDescription, itemNames, itemDescriptions, itemTypes); 

のようなものを使用して構築することができ

、typeDescriptionは文字列です。 itemNamesとitemDescriptionsはString []です。 itemTypesはOpenType []です。 SimpleTypeとCompositeTypeを使用してOpenTypeを構築できます。

すべてこのオブジェクトは

import javax.management.openmbean.*; 
でインポートする必要があります
関連する問題