我已经创建了一个我想从MBean方法返回的自定义JavaBean。以下是自定义JavaBean:
package org.text.jmx;
public class Person {
private firstName;
private lastName;
public Person(){
}
public Person(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
MBean接口如下:
package org.text.jmx;
public interface TestJmxMBean {
public Person getPerson();
public void setPerson(String firstName, String lastName);
}
实现MBean的类:
package org.text.jmx;
public class TestJmx implements TestJmxMBean {
private Person person = new Person();
public Person getPerson() {
return person;
}
public void setPerson(String firstName, String lastName) {
person.setFirstName(firstName);
person.setLastName(lastName);
}
}
我创建了一个注册上述MBean的服务器应用程序,这是成功的。我创建了一个客户端应用程序,它通过JMX成功连接到服务器应用程序,但是当我从客户端应用程序调用testJmx.getPerson()方法时收到一个错误,它无法返回Person对象。我究竟做错了什么?它工作得很好我只是从TestJmx.getPerson()中定义返回类型,如String或String []。