[英]How do I get the beans that spring has registered with jmx?
有沒有一種方法可以獲取Spring已在mbeanserver中注冊的bean實例列表?
我看到您可以在MBeanExporter上注冊MBeanExporterListener,但這僅告訴我注冊了bean的ObjectName。 我可以在某個地方使用該ObjectName來獲取已注冊對象的實例嗎?
我看到一個選擇可能是子類化MBeanExporter,但是我真的不想這樣做,除非必須這樣做。
謝謝。
原來你做不到。 如果要實現此目標,則必須子類化MBeanExporter。
我已經測試了以下示例代碼
// Get the Platform MBean Server
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Construct the ObjectName for the MBean we will register
ObjectName name = new ObjectName("com.example.mbeans:type=Hello");
// Create the Hello World MBean
Hello mbean = new Hello();
// Register the Hello World MBean
mbs.registerMBean(mbean, name);
Set<ObjectInstance> instances = mbs.queryMBeans(name, null);
ObjectInstance instance = (ObjectInstance) instances.toArray()[0];
System.out.println("Class Name:t" + instance.getClassName());
System.out.println("Object Name:t" + instance.getObjectName());
// Wait forever
System.out.println("Waiting forever...");
Thread.sleep(Long.MAX_VALUE);
當然有interface HelloMBean
和
class Hello extends NotificationBroadcasterSupport implements HelloMBean
輸出是
Class Name:tcom.example.mbeans.Hello
Object Name:tcom.example.mbeans:type=Hello
Waiting forever...
希望這可以幫助!
更新:
public class ObjectInstance extends Object implements Serializable
。 ObjectInstance表示MBean的對象名稱及其類名稱。 我們無法檢索對對象本身的引用。
我猜對已注冊的mbean進行操作的唯一方法是使用JMS / RMI連接器(或HTML適配器)來獲得mbaean服務器的連接,使用與已注冊的mbean對應的JMX.newMBeanProxy創建mbaen代理並在其上調用方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.