Spring集成JMX是很简单的,这里通过注解发方式暴露JMX,有的时序我们需要监听JMX属性的改变,下面我们在Spring配置文件中配置监听器。
涉及到三个重要的annotation:@ManagedResource @ManagedAttribute 和 @ManagedOperation。
用途 Commons Attributes属性 JDK 5.0注解 属性/注解类型
| 将类的所有实例标识为JMX受控资源 | ManagedResource |
@ManagedResource |
Class 类 |
| 将方法标识为JMX操作 | ManagedOperation |
@ManagedOperation |
Method方法 |
| 将getter或者setter标识为部分JMX属性 | ManagedAttribute |
@ManagedAttribute |
Method (only getters and setters) 方法(仅getters和setters) |
| 定义操作参数说明 | ManagedOperationParameter |
@ManagedOperationParameter和@ManagedOperationParameters |
Method 方法 |
| Parameter | Description | Applies to |
|---|---|---|
| ObjectName | Used by MetadataNamingStrategy to determine the ObjectName of a managed resource | ManagedResource |
| description | Sets the friendly description of the resource, attribute or operation | ManagedResource, ManagedAttribute, ManagedOperation, ManagedOperationParameter |
| currencyTimeLimit | Sets the value of the currencyTimeLimit descriptor field | ManagedResource, ManagedAttribute |
| defaultValue | Sets the value of the defaultValue descriptor field | ManagedAttribute |
| log | Sets the value of the log descriptor field | ManagedResource |
| logFile | Sets the value of the logFile descriptor field | ManagedResource |
| persistPolicy | Sets the value of the persistPolicy descriptor field | ManagedResource |
| persistPeriod | Sets the value of the persistPeriod descriptor field | ManagedResource |
| persistLocation | Sets the value of the persistLocation descriptor field | ManagedResource |
| persistName | Sets the value of the persistName descriptor field | ManagedResource |
| name | Sets the display name of an operatio |

这篇博客介绍了如何在Spring中通过注解方式将Bean暴露为带通知的MBean,详细阐述了@ManagedResource、@ManagedAttribute和@ManagedOperation的使用。同时,文章讲解了JMX的属性改变通知机制,利用AttributeChangeNotification实现观察者设计模式,并展示了如何配置监听器以响应属性变更。通过JConsole控制台和Eclipse控制台,可以观察到通知监听的效果。
最低0.47元/天 解锁文章
2717

被折叠的 条评论
为什么被折叠?



