Spring MBean的官方文档路径
http://docs.spring.io/spring/docs/3.0.x/reference/jmx.html
参考文档
http://lionbule.iteye.com/blog/771727
1, spring bean 文件中加命名空间
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
2,配置mbeanServer
<context:mbean-server id="mbeanServer" />
<context:mbean-export server="mbeanServer" />\
3, 代码中配置
- @ManagedResource(objectName="bean:name=lionbuleTest", description="My Managed Bean")
- public class AnnotationTestMBean{
- private String name;
- private int age;
- @ManagedAttribute(description="The Name Attribute")
- public void setName(String name) {
- this.name = name;
- }
- @ManagedAttribute()
- public String getName() {
- return name;
- }
- public int getAge() {
- return age;
- }
- public void setAge(int age) {
- this.age = age;
- }
- @ManagedOperation(description="Add two numbers")
- @ManagedOperationParameters({
- @ManagedOperationParameter(name = "x", description = "The first number"),
- @ManagedOperationParameter(name = "y", description = "The second number")})
- public int add_1(int x, int y) {
- return x + y;
- }
- @ManagedOperation
- public int add_2(int x, int y){
- return x + y;
- }
- public void dontExposeMe() {
- throw new RuntimeException();
- }
- }