JMXBeanWrapper无法使用修饰符“ public”访问类“ JMX”的成员

问题描述

我正在尝试使用JMXWrapper类/项目

对于当前项目的一组JMX类,它们全都可以在JConsole或VisualVM上正常工作

对于其中之一,我尝试适应JMXWrapper或与之合作:

public interface MainJmxMBean {

    boolean showIfMainIsRunning();

    void stopMain();

}

@JMXBean(description="Administrates the Main app",sorted=true)
class MainJmx implements MainJmxMBean {

    private boolean isMainRunning;

    MainJmx() {
        isMainRunning =true;
    }


    @Override
    @JMXBeanoperation(name="Show If Main Is Running",description="Shows if the Main app is running or not",sortValue="1")
    public boolean showIfMainIsRunning() {
        return isMainRunning;
    }


    @Override
    @JMXBeanoperation(description="Stops the Main app",sortValue="2")
    public void stopMain() {
        isMainRunning = false;
    }

}

注意:上面显示的类无需注释即可正常工作。现在被注释以改善信息及其在JConsole / VisualVM中的使用

最后

private void registerMBeanWithJMXBeanWrapper(ObjectJmxMBean objectJmxMBean) {

    try {
        //System.out.printf("%s %n",objectJmxMBean.toString());
        ObjectName objectName = new ObjectName(objectJmxMBean.getName());
        server.registerMBean(new JMXBeanWrapper(objectJmxMBean.getobject()),objectName);
    }
    catch(MalformedobjectNameException |
          InstanceAlreadyExistsException |
          MBeanRegistrationException |
          NotCompliantMBeanException |
          IntrospectionException e) {
        System.err.printf("[CanonicalName] %s - ERROR: %s %n",e.getClass().getCanonicalName(),e.getMessage());
    }

}

上面的重要部分是:new JMXBeanWrapper(objectJmxMBean.getobject())

直到这里,我都按照JMXBeanWrapper文档进行了所有说明,这些文档在这文章顶部的链接中甚至从作者的帖子中共享:

当我通过JConsole或VisualVM运行Main应用程序时,我可以看到正在应用的批注以及预期的工作方式,因此直到这里看来目标已经实现。

enter image description here

enter image description here

问题:问题是当我确实单击其中的任何一个时出现了:

enter image description here

完整的错误消息是:

Problem invoking stopMain: 
java.lang.illegalaccessexception 
Class com.udojava.jmx.wrapper.JMXBeanWrapper can not access a member of class 
com.manuel.jordan.jmx.admin.MainJmx with modifiers "public"

观察: 似乎错误直接由JConsole或VisualVM引发,因为根据JMXBeanWrapper.java代码,没有{{1} }以及该消息的一部分throw new illegalaccessexception

注意与观察::根据Github上共享的项目,它已经在JDK 6上进行了测试,而我正在使用/正在使用JDK 8。

配置中可能存在什么错误或缺失?

解决方法

解决方案如下:

编辑自:

@JMXBean(description="Administrates the Main app",sorted=true)
class MainJmx implements MainJmxMBean {

    private boolean isMainRunning;

    MainJmx() {
        isMainRunning =true;
    }

收件人

@JMXBean(description="Administrates the Main app",sorted=true)
public class MainJmx implements MainJmxMBean {

    private boolean isMainRunning;

    MainJmx() {
        isMainRunning =true;
    }

结论JMXWrapper需要用@JMXBean注释的类必须为public

您如何看待构造函数仍为package default