熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

spring和jmx

2022-06-13   來源: Java開源技術 

  <?xml version= encoding=UTF?>

  <beans xmlns=

  xmlns:xsi=instance

  xsi:schemaLocation= beansxsd>

  <bean id=mbeanManager

  class=servermbeanMBeanManager />

  <bean id=mbeanTest

  class=servermbeanMBeanTest />

  <bean id=mbeanServer

  class=orgspringframeworkjmxsupportMBeanServerFactoryBean>

  </bean>

  <bean id=assembler

  class=orgspringframeworkjmxexportassemblerMetadataMBeanInfoAssembler>

  <property name=attributeSource ref=jmxAttributeSource />

  </bean>

  <bean id=jmxAttributeSource

  class=orgspringframeworkjmxexportannotationAnnotationJmxAttributeSource />

  <bean id=mBeanExporter

  class=orgspringframeworkjmxexportMBeanExporter>

  <property name=server ref=mbeanServer />

  <property name=assembler ref=assembler />

  <property name=beans>

  <map>

  <entry key=eci:name=testBean

  valueref=mbeanTest />

  <entry key=eci:name=manageBean

  valueref=mbeanManager />

  </map>

  </property>

  <property name=notificationListeners>

  <list>

  <bean

  class=orgspringframeworkjmxexportNotificationListenerBean>

  <constructorarg ref=testNotificationListener />

  <property name=mappedObjectNames>

  <list>

  <value>eci:name=testBean</value>

  <value>eci:name=manageBean</value>

  </list>

  </property>

  <property name=notificationFilter

  ref=testNotificationListener />

  </bean>

  </list>

  </property>

  </bean>

  <bean id=testNotificationListener class=servernotificationTestNotificationListener/>

  <bean id=registry class=orgspringframeworkremotingrmiRmiRegistryFactoryBean>

  <property name=port value=/>

  </bean>

  <bean id=serverConnector

  class=orgspringframeworkjmxsupportConnectorServerFactoryBean >

  <property name=serviceUrl  value=service:jmx:rmi://localhost/jndi/rmi://localhost:/eci/>

  <!<property name=environment>

  <map>

  <entry key=jmxremotexpasswordfile>

  <value>jmxremotepassword</value>

  </entry>

  <entry key=jmxremotexaccessfile>

  <value>jmxremoteaccess</value>

  </entry>

  </map>

  </property>>

  </bean>

  </beans>

  針對environment設置需要補充下

  這是針對安全設置的jmxremotepasswordjmxremoteaccess分別是保存的訪問權限的信息和密碼這兩個是文 件這兩個文件可以參考在jdk目錄下的\jre\lib\management下的模板我們可以根據不同的安全來確定是否需要設置用戶名和密碼

  java文件讀入spring配置文件並啟動jmx server

  Java 代碼

  package servermain;

  import orgntextsupport*;

  public class ServerMain {

  public static void main(String[] args) {

  @SuppressWarnings(unused)

  ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(

  /jmxServerContextxml);

  while (true) {

  try {

  Threadsleep();

  } catch (InterruptedException e) {

  eprintStackTrace();

  }

  }

  }

  }


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28540.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.