2012-01-18 6 views
3

[email protected]을 사용하여 메서드를 MBean으로 노출했습니다.Spring의 @ManagedOperation 이름 JMX

메서드 이름과 다른 작업 이름을 원하지만 관리되는 작업에 해당 속성이 없습니다.

예를 들어

:

@ManagedOperation 
public synchronized void clearCache() 
{ 
    // do something 
} 

나는 이름 = "ResetCache"로 노출이 작업을 할 수 있습니다.

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를 연결할 경우 작동시킬 수 있어야합니다 :

@Retention(RetentionPolicy.RUNTIME) 
@Target(ElementType.METHOD) 
public @interface JmxName { 
    String value(); 
} 

그리고 MetadataMBeanInfoAssembler의 사용자 정의 서브 클래스 :

답변

5

사용자 정의 주석을 작성

<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> 
+0

당신의 솔루션에 대해 고맙지 만,이 솔루션은 메소드 조작의 설명을 변경하지만 조작의 변경 이름을 원하기 때문에 나를 도울 수 없습니다. – MJM

+0

@MJM ok,이 업데이트 된 솔루션을 대신 사용해보십시오 –

+0

"업데이트 된 솔루션"을 찾지 못했습니다. – MJM

9

나는 단지 de legates to clearCache(). 인터페이스 이름이 혼란 스러울 때마다이 작업을 수행합니다. @ManagedOperation 안에있는 description = "resets the cache"도 좋은 아이디어 일 수 있습니다.

@ManagedOperation(description = "resets the cache") 
public void resetCache() { 
    clearCache(); 
} 
+4

+1 간단하고 효과적입니다 – skaffman