Java Reference
In-Depth Information
After setting the default domain to bean , the documentReplicator bean will be exported under the
following MBean object name:
Moreover, you can specify a bean's MBean object name in the objectName attribute of the
@ManagedResource annotation. For example, you can export your file copier as an MBean by annotating it
with the following annotations:
package com.apress.springenterpriserecipes.replicator;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;
objectName = "bean:name=fileCopier,type=FileCopierImpl",
description = "File Copier")
public class FileCopierImpl implements FileCopier {
description = "Copy file from source directory to destination directory")
@ManagedOperationParameters( {
name = "srcDir", description = "Source directory"),
name = "destDir", description = "Destination directory"),
name = "filename", description = "File to copy") })
public void copyFile(String srcDir, String destDir, String filename)
throws IOException {
However, specifying the object name in this way works only for classes that you're going to create a
single instance of in the IoC container (e.g., file copier), not for classes that you may create multiple
instances of (e.g., file replicator). This is because you can only specify a single object name for a class. As
a result, you shouldn't try and run the same server multiple times without changing the names.
You can simply declare a <context:mbean-export> element in your bean configuration file, instead
of the AnnotationMBeanExporter declaration, which you can omit.
<beans xmlns=""
<context:mbean-export server="mbeanServer" default-domain="bean" />
Search WWH ::

Custom Search