JMXBeanWrapper无法访问具有修饰符“public”的类“JMX”的成员。

huangapple go评论71阅读模式
英文:

JMXBeanWrapper can not access a member of class "JMX" with modifiers "public"

问题

我正在尝试使用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 {
		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运行主应用程序时,我可以看到注解被应用并且按预期工作,因此到这里为止目标似乎已经实现。

问题: 问题在于当我点击它们中的任何一个时会出现:

完整的错误消息是:

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

观察: _似乎_错误是直接由JConsole或VisualVM引发的,因为根据JMXBeanWrapper.java源代码,在该消息的部分"with modifiers "public"" 中没有throw new IllegalAccessException语句。

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

在配置中可能出了什么问题或遗漏了什么?

英文:

I am trying to use the JMXWrapper class/project

For a current project for a set of JMX classes all of them work in peace on either JConsole or VisualVM

For one of them I tried to adapt or work with JMXWrapper:

public interface MainJmxMBean {

	boolean showIfMainIsRunning();

	void stopMain();

}

and

@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;
	}

}

Note: The class shown above works fine without the annotations. Now was annotated to improve the information and its use in JConsole/VisualVM

And finally

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());
	}

}

The important part of above is: new JMXBeanWrapper(objectJmxMBean.getObject())

Until here I did do all the instructions according with the JMXBeanWrapper documentation shared in the link in the top of this post and even from the author's post:

When I run the Main app, through either JConsole or VisualVM I can see the annotations being applied and working how is expected, therefore until here the goal seems been accomplished.

JMXBeanWrapper无法访问具有修饰符“public”的类“JMX”的成员。

JMXBeanWrapper无法访问具有修饰符“public”的类“JMX”的成员。

Problem: the problem is when I do click to either of them arises:

JMXBeanWrapper无法访问具有修饰符“public”的类“JMX”的成员。

The complete error message is:

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"

Observation: seems the error is thrown directly by JConsole or VisualVM, because according with the JMXBeanWrapper.java source code, there is no the throw new IllegalAccessException statement with the part of that message with modifiers "public"

Note & Observation: according with the project shared on Github, it was tested with JDK 6 and I am using/working with JDK 8.

What could be wrong or missing in the configuration?

答案1

得分: 0

以下是翻译好的内容:

解决方案如下:

从:

@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

英文:

The solution is the following:

Edit from:

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

    private boolean isMainRunning;

    MainJmx() {
        isMainRunning =true;
    }

To

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

    private boolean isMainRunning;

    MainJmx() {
        isMainRunning =true;
    }

Conclusion: the JMXWrapper needs that the class annotated with @JMXBean must be public.

How you can see the constructor can remain being package default

huangapple
  • 本文由 发表于 2020年10月9日 05:39:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/64271004.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定