Java Reference
In-Depth Information
If, on the other hand, you have multiple MBeans servers running, you need to tell the mbeanServer
bean to which server it should bind. You do this by specifying the agentId of the server. To figure out
the agentId of a given server, browse to the JMImplementation/MBeanServerDelegate/Attributes/
MBeanServerId node of the server you're inspecting in JConsole. There, you'll see the string value. On
this author's local machine, the value is workstation_1253860476443 . To enable it, configure the agentId
property of the MBeanServer.
<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
<property name="agentId" value="workstation_1253860476443" />
</bean>
If you have multiple MBean server instances in your context, you can explicitly specify a specific
MBean server for MBeanExporter to export your MBeans to. In this case, MBeanExporter will not locate
an MBean server; it will use the specified MBean server instance. This property is for you to specify a
particular MBean server when more than one is available.
<beans ...>
...
<bean id="mbeanServer"
class="org.springframework.jmx.support.MBeanServerFactoryBean">
<property name="locateExistingServerIfPossible" value="true" />
</bean>
<bean id="mbeanExporter"
class="org.springframework.jmx.export.MBeanExporter">
...
<property name="server" ref="mbeanServer" />
</bean>
</beans>
The Main class for exporting an MBean can be simplified as shown following. You have to retain the
key-requesting statement to prevent your application from terminating.
package com.apress.springenterpriserecipes.replicator;
...
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Main {
public static void main(String[] args) throws IOException {
new ClassPathXmlApplicationContext("beans.xml");
System.in.read();
}
}
Exposing MBeans for Remote Access
If you want your MBeans to be accessed remotely, you need to enable a remoting protocol for JMX.
JSR-160 defines a standard for JMX remoting through a JMX connector. Spring allows you to create a
JMX connector server through ConnectorServerFactoryBean .
Search WWH ::




Custom Search