只是在本地tomcat服务器上的eclipse中尝试一个简单的Spring JMX应用程序,但似乎无法注册mbeans,以便在eclipse上下文中可以在jconsole中查看:component-scan确实可以获取bean我已创建,但这些都没有注册。以编程方式注册mbeans时,它可以工作。
这是我的config xml文件。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<bean id="mbeanServer" class="java.lang.management.ManagementFactory"
lazy-init="false" factory-method="getPlatformMBeanServer">
</bean>
<context:component-scan base-package="com.jmx.beans" />
<context:mbean-export server="mbeanServer" />
</beans>
我试图用注释注册的简单bean
package com.jmx.beans;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;
@Component
@ManagedResource(objectName="bean:name=Hello")
public class Hello{
String message = null;
@ManagedAttribute(description="get the message")
public String getMessage(){
return this.message;
}
@ManagedAttribute(description="set the message")
public void setMessage(String Message){
this.message = Message;
}
}
我还设置了tomcat服务器争论如下
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9990
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.hostname="localhost"
非常感谢任何帮助,谢谢
答案 0 :(得分:3)
为什么要修改帖子以删除<context:component-scan/>
?这需要找到您的@Component
。
我刚刚测试过,一切都很适合我...
@Component
@ManagedResource
public class Foo {
@ManagedAttribute
public int getIt() {
return 42;
}
}
和
<context:mbean-server/>
<context:component-scan base-package="foo" />
<context:mbean-export/>
我尝试了你的MBean服务器风格,并且也有效。