Java Reference
In-Depth Information
@ManagedAttribute(description = "Set source directory")
public void setSrcDir(String srcDir) {
...
}
@ManagedAttribute(description = "Get destination directory")
public String getDestDir() {
...
}
@ManagedAttribute(description = "Set destination directory")
public void setDestDir(String destDir) {
...
}
...
@ManagedOperation(description = "Replicate files")
public synchronized void replicate() throws IOException {
...
}
}
Auto-Detecting MBeans by Annotations
In addition to exporting a bean explicitly with
MBeanExporter
, you can simply configure its subclass
AnnotationMBeanExporter
to auto-detect MBeans from beans declared in the IoC container. You needn't
configure an MBean assembler for this exporter because it uses
MetadataMBeanInfoAssembler
with
AnnotationJmxAttributeSource
by default. You can delete the previous
beans
and
assembler
properties
for this exporter.
<bean id="mbeanExporter"
class="org.springframework.jmx.export.
annotation.AnnotationMBeanExporter">
...
</bean>
AnnotationMBeanExporter
detects any beans configured in the IoC container with the
@ManagedResource
annotation and exports them as MBeans. By default, this exporter exports a bean to
the domain whose name is the same as its package name. Also, it uses the bean's name in the IoC
container as its MBean name, and the bean's short class name as its type. So your
documentReplicator
bean will be exported under the following MBean object name:
com.apress.springenterpriserecipes.replicator:name=documentReplicator,
➥
type=FileReplicatorJMXImpl
If you don't want to use the package name as the domain name, you can set the default domain for
this exporter.
<bean id="mbeanExporter"
class="org.springframework.jmx.export.annotation.AnnotationMBeanExporter">
...
<property name="defaultDomain" value="bean" />
</bean>
Search WWH ::
Custom Search