spring 和jmx

http://static.springsource.org/spring/docs/2.5.6/reference/jmx.html

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> 

<bean id="mbeanManager" 
class="server.mbean.MBeanManager" /> 
<bean id="mbeanTest" 
class="server.mbean.MBeanTest" />   


<bean id="mbeanServer" 
class="org.springframework.jmx.support.MBeanServerFactoryBean"> 
</bean>


<bean id="assembler" 
class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> 
<property name="attributeSource" ref="jmxAttributeSource" />
</bean> 

<bean id="jmxAttributeSource" 
class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /> 

<bean id="mBeanExporter"
class="org.springframework.jmx.export.MBeanExporter"> 
<property name="server" ref="mbeanServer" /> 
<property name="assembler" ref="assembler" /> 
<property name="beans"> 
<map> 
<entry key="eci:name=testBean" 
value-ref="mbeanTest" />
<entry key="eci:name=manageBean" 
value-ref="mbeanManager" /> 
</map> 
</property>
<property name="notificationListeners"> 
<list> 
<bean 
class="org.springframework.jmx.export.NotificationListenerBean"> 
<constructor-arg 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="server.notification.TestNotificationListener"/>
<bean id="registry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean">
<property name="port" value="9876"/>
</bean>

<bean id="serverConnector" 
class="org.springframework.jmx.support.ConnectorServerFactoryBean" >
<property name="serviceUrl"  value="service:jmx:rmi://localhost/jndi/rmi://localhost:9876/eci"/>
<!--<property name="environment">
<map>
<entry key="jmx.remote.x.password.file">
<value>jmxremote.password</value>
</entry>
<entry key="jmx.remote.x.access.file">
<value>jmxremote.access</value>
</entry>
</map>
</property>-->
</bean>
</beans> 

针对environment设置,需要补充下。

这是针对安全设置的,jmxremote.password,jmxremote.access分别是保存的访问权限的信息和密码。这两个是文 件,这两个文件可以参考在jdk目录下的\jre\lib\management下的模板。我们可以根据不同的安全来确定是否需要设置用户名和密码。

java文件读入spring配置文件,并启动jmx server。
Java 代码
  1. package server.main;  
  2. import org.springframework.context.support.*;  
  3.   
  4. public class ServerMain {  
  5.   
  6.     public static void main(String[] args) {  
  7.         @SuppressWarnings("unused")  
  8.         ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(  
  9.                 "/jmxServerContext.xml");  
  10.         while (true) {  
  11.             try {  
  12.                 Thread.sleep(1000);  
  13.             } catch (InterruptedException e) {  
  14.                 e.printStackTrace();  
  15.             }  
  16.         }  
  17.     }  
  18.   

posted on 2010-06-10 09:04  dhj  阅读(186)  评论(0编辑  收藏  举报

导航