【问题标题】:JXM MXBean custom attributesJXM MXBean 自定义属性
【发布时间】:2014-08-20 07:56:16
【问题描述】:

我遇到了 MXBean 自定义类型的问题,我无法处理它。这是我的java结构,涉及Map< enum, OtherThing>属性

PPV及其界面

public class PPV implements PPVMXBean {

   public enum EnumPV {
      PV1,
      PV2;
   }

   public static Map<EnumPV, PV> list;

   public Map<EnumPV, PV> getList() {
       return list;
   }
}

public interface PPVMXBean {
    public Map<EnumPV, PV> getList();
}

PV及其接口

public class PV implements PVBean {

   public enum EnumTP {
      TP1,
      TP2;
   }

   private Map<EnumTP, EnumP[]> mapP;
   private Map<EnumTP, EnumP[]> mapC;
   private Map<EnumTP, EnumP[]> mapT;
   private Map<EnumTP, EnumP[]> mapV;

   public Map<EnumTP, EnumP[]> getMapP() {
      return mapP;
   }

   public Map<EnumTP, EnumP[]> getMapC() {
      return mapC;
   }

   public Map<EnumTP, EnumP[]> getMapT() {
      return mapT;
   }

   public Map<EnumTP, EnumP[]> getMapV() {
      return mapV;
   }
}

public interface PVBean {
    public Map<EnumTP, EnumP[]> getMapP();
    public Map<EnumTP, EnumP[]> getMapC();
    public Map<EnumTP, EnumP[]> getMapT();
    public Map<EnumTP, EnumP[]> getMapV();
}

枚举P

public enum EnumP {
    P1(1),
    P2(2);

    private int p;

    EnumP (int pAux) {
        p = pAux;
    }    

    public int getP() {
       return p;
    }        
}

通过所有这些,我得到:

...
Caused by: javax.management.NotCompliantMBeanException: com.example.PPVMXBean: Method com.example.PPVMXBean.getLista has parameter or return type that cannot be translated into an open type
...
Caused by: java.lang.IllegalArgumentException: Method com.example.PPVMXBean.getLista has parameter or return type that cannot be translated into an open type
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.util.Map<com.example.PPV$EnumPV, com.examplePV>
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: class com.example.PV
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.lang.Class<?>
...
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: java.lang.Class<?>

我做错了什么?问题出在哪里?

【问题讨论】:

    标签: java jmx mbeans mxbean


    【解决方案1】:

    当你写作时:

    public interface PVBean {
        public Map<EnumTP, EnumP[]> getMapP();
        public Map<EnumTP, EnumP[]> getMapC();
        public Map<EnumTP, EnumP[]> getMapT();
        public Map<EnumTP, EnumP[]> getMapV();
    }
    

    ... EnumTP 在范围内如何?

    【讨论】:

    • EnumTP 在 PV 内部(在顶部)。是这个意思吗?
    • Interface PVBean 没有关于 EnumTP 是什么的信息,因为唯一的 EnumTP 在 PV 的内部范围内。
    • 我省略了所有类的所有导入。 PVBean 具有 EnumTP 导入。此外,EnumP 的类型是 'enum',我认为 enum 类型不需要其他任何东西(如 String 或 int)
    • 有同样问题的人吗?
    猜你喜欢
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    • 2011-03-27
    • 2011-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多