![](/img/trans.png)
[英]AttributeNotFoundException through JMX in Startup bean on Wildfly
[英]Error while publishing Bean through JMX
我正在嘗試在JMX上注冊bean。 我在mbs.registerMBean(metadataObj, name);
行上遇到錯誤mbs.registerMBean(metadataObj, name);
。 錯誤說
Multiple markers at this line
- Syntax error on token "(", delete
this token
- Syntax error on token ")", delete
this token
我不知道這是怎么回事。
該bean具有有關請求開始/結束時間的基本元數據。 類
package test.performance;
public class RequestPerformanceMetadata implements PerformanceMetadataMBean{
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
PerformanceMetadataMBean metadataObj = new RequestPerformanceMetadata();
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
ObjectName name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(metadataObj, name);
public double getTimeTook() {
return timeTook;
}
public void setTimeTook(double timeTook) {
this.timeTook = timeTook;
}
接口
package test.performance;
public interface PerformanceMetadataMBean {
double getTimeTook();
void setTimeTook(double timeTook);
String getRequestType();
void setRequestType(String requestType);
上
這里有很多問題。
從msb = ....開始,沒有方法....它必須存在於方法中。 接下來, 新的ObjectName(...)引發異常,因此您需要將其包裝在try / catch塊中。 另外,你確定你想創建RequestPerformanceMetadata 內 RequestPerformanceMetadata的另一個實例? 也許您只想注冊此實例。
看一下這段代碼片段:
class RequestPerformanceMetadata implements PerformanceMetadataMBean {
private double startTime;
private double endTime;
private double timeTook;
private String requestType;
private int numOfRequests;
private MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
private ObjectName name;
public RequestPerformanceMetadata() {
try {
name = new ObjectName("test.performace:type=PerformanceMetadataMBean");
mbs.registerMBean(this, name);
} catch (Exception ex) {
throw new RuntimeException("Yo dog. Bad object name", ex);
}
}
//........... snip ...........
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.