2013-03-14 85 views
0

蚀内就尝试了一个简单的Spring JMX应用程序的本地Tomcat服务器上,但似乎无法注册的MBean让他们再成为提供给内JConsole的查看已注册,日食范围内:组件扫描似乎拿起我创建的bean,但是这些没有注册。以编程方式注册mbeans时,它可以工作。春天的JMX MBean没有出现或者与JConsole的

这是我的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我试图如下

-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" 

与注解注册

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服务器arguements任何帮助将不胜感激感谢

回答

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服务器的风格尝试过了,这工作太。

+0

删除了一些评论的东西,并意外删除了组件扫描。谢谢,它仍然无法正常工作,我错过了什么?也许不同的文件夹结构 – ashley 2013-03-14 16:02:14

+0

不 - 我只是将com.jmx.beans.Hello类添加到我的项目中,并将基本包更改为com.jmx.beans,并且它显示得很好。我建议你打开DEBUG日志记录;你应该最终得到一个INFO日志“... AnnotationMBeanExporter]名为'hello'的Bean已经被自动检测为JMX暴露” – 2013-03-14 16:10:54

+0

感谢但仍然没有快乐,我看不到还有什么我失踪了,没有似乎很多完整的教程,所以我可能会看到我错了。我有一种感觉,它与我的弹簧罐有关 – ashley 2013-03-14 21:16:49