我曾经org.springframework.jmx.export.annotation.@ManagedOperation
将一个方法公开为 MBean。
我希望操作名称与方法名称不同,但托管操作没有任何属性。
例如:
@ManagedOperation
public synchronized void clearCache()
{
// do something
}
我希望这个操作以 name = "ResetCache" 公开。
我曾经org.springframework.jmx.export.annotation.@ManagedOperation
将一个方法公开为 MBean。
我希望操作名称与方法名称不同,但托管操作没有任何属性。
例如:
@ManagedOperation
public synchronized void clearCache()
{
// do something
}
我希望这个操作以 name = "ResetCache" 公开。
我只想定义另一个仅委托给clearCache()
. 当接口名称令人困惑时,我们总是这样做。description = "resets the cache"
内部@ManagedOperation
也可能是一个好主意。
@ManagedOperation(description = "resets the cache")
public void resetCache() {
clearCache();
}
创建自定义注释:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface JmxName {
String value();
}
和一个自定义子类MetadataMBeanInfoAssembler
:
public class CustomMetadataMBeanInfoAssembler extends MetadataMBeanInfoAssembler {
private String getName(final Method method) {
final JmxName annotation = method.getAnnotation(JmxName.class);
if (annotation != null) {
return annotation.value();
}else
return method.getName();
}
}
protected ModelMBeanOperationInfo createModelMBeanOperationInfo(Method method, String name, String beanKey) {
return new ModelMBeanOperationInfo(getName(method),
getOperationDescription(method, beanKey),
getOperationParameters(method, beanKey),
method.getReturnType().getName(),
MBeanOperationInfo.UNKNOWN);
}
}
如果你连接 CustomMetadataMBeanInfoAssembler (并使用注释),你应该让它工作:
<bean id="jmxAttributeSource"
class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
<!-- will create management interface using annotation metadata -->
<bean id="assembler"
class="com.yourcompany.some.path.CustomMetadataMBeanInfoAssembler">
<property name="attributeSource" ref="jmxAttributeSource"/>
</bean>