无法通过Spring注册MBean

坦维尔

我正在尝试使用Spring导出带注释的MBean。但是遇到以下异常(尝试在tomcat7上部署时):

javax.management.MalformedObjectNameException: Key properties cannot be empty

这是我的JmxTestBean类:

package com.i2gether.service.jmx;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedOperationParameter;
import org.springframework.jmx.export.annotation.ManagedOperationParameters;
import org.springframework.jmx.export.annotation.ManagedResource;

@ManagedResource(description = "My Managed Bean")
public class JmxTestBean {

    private String name;
    private int age;

    @ManagedAttribute(description = "The Age Attribute")
    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @ManagedAttribute(description = "The Name Attribute")
    public void setName(String name) {
        this.name = name;
    }

    @ManagedAttribute(defaultValue = "foo")
    public String getName() {
        return name;
    }

    @ManagedOperation(description = "Add two numbers")
    @ManagedOperationParameters({ @ManagedOperationParameter(name = "x", description = "The first number"),
            @ManagedOperationParameter(name = "y", description = "The second number") })
    public int add(int x, int y) {
        return x + y;
    }

    public void dontExposeMe() {
        throw new RuntimeException();
    }

}

这是我的Spring上下文配置中的相关部分:

<beans xmlns="http://www.springframework.org/schema/beans" ...>

    <context:component-scan base-package="com.i2gether.service" />

    <context:mbean-export />

    <bean id="serviceLayerExporter" class="org.springframework.jmx.export.MBeanExporter"  lazy-init="false">
        <!-- notice how no beans are explicitly configured here -->
        <property name="autodetect" value="true" />
        <property name="assembler" ref="assembler" />
    </bean>

    <bean id="testBean" class="com.i2gether.service.jmx.JmxTestBean">
        <property name="name" value="TEST" />
        <property name="age" value="100" />
    </bean>

    <bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
        <property name="attributeSource">
            <bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" />
        </property>
    </bean>

</beans>

最后,错误日志如下所示:

11:52:25.794 [pool-2-thread-1] ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serviceLayerExporter' defined in class path resource [appcontext.xml]: Invocation of init method failed; nested exception is org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [[email protected]] with key 'testBean'; nested exception is javax.management.MalformedObjectNameException: Key properties cannot be empty
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) ~[spring-web-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779) ~[catalina.jar:7.0.27]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273) ~[catalina.jar:7.0.27]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[catalina.jar:7.0.27]
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:895) ~[catalina.jar:7.0.27]
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871) ~[catalina.jar:7.0.27]
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615) ~[catalina.jar:7.0.27]
        at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:649) ~[catalina.jar:7.0.27]
        at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1585) ~[catalina.jar:7.0.27]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) ~[na:1.7.0_25]
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) ~[na:1.7.0_25]
        at java.util.concurrent.FutureTask.run(FutureTask.java:166) ~[na:1.7.0_25]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) ~[na:1.7.0_25]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) ~[na:1.7.0_25]
        at java.lang.Thread.run(Thread.java:724) ~[na:1.7.0_25]
Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [[email protected]] with key 'testBean'; nested exception is javax.management.MalformedObjectNameException: Key properties cannot be empty
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:610) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:535) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:417) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        ... 26 common frames omitted
Caused by: javax.management.MalformedObjectNameException: Key properties cannot be empty
        at javax.management.ObjectName.construct(ObjectName.java:483) ~[na:1.7.0_25]
        at javax.management.ObjectName.<init>(ObjectName.java:1382) ~[na:1.7.0_25]
        at javax.management.ObjectName.getInstance(ObjectName.java:1273) ~[na:1.7.0_25]
        at org.springframework.jmx.support.ObjectNameManager.getInstance(ObjectNameManager.java:62) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.naming.KeyNamingStrategy.getObjectName(KeyNamingStrategy.java:142) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.getObjectName(MBeanExporter.java:736) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:639) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:600) ~[spring-context-4.0.3.RELEASE.jar:4.0.3.RELEASE]
        ... 30 common frames omitted

有人可以指出我在做什么错吗?

罗曼

您应该为@ManagedResource批注指定objectName属性。

在这里您可以找到@Dude Spring MBeanExporter的详细说明-为MBean命名

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法通过TestFlight安装应用:注册的最大设备数量

来自分类Dev

注册Oracle JDBC可诊断性MBean时出错

来自分类Dev

Windows 8无法通过批处理运行注册表文件

来自分类Dev

带有水豚的Selenium无法通过devise登录/注册

来自分类Dev

IBM Worklight 6.2:JMX配置错误。无法获得MBean

来自分类Dev

关闭Spring Boot应用程序时无法注销DataSource JMX MBean

来自分类Dev

通过python更改注册表无法正常工作

来自分类Dev

Spring-是否可以获取所有通过@ComponentScan注册的软件包?

来自分类Dev

Spring JMX-将包中的类注册为MBean

来自分类Dev

无法通过登录活动通过网络服务发送注册ID(GCM)

来自分类Dev

如何使用方法getPlatformMXBean()获取注册MBean?

来自分类Dev

Spring JMX-<context:mbean-server>的用途

来自分类Dev

如何通过代码注册Spring ApplicationListener实现?

来自分类Dev

无法通过TLS推送到私有Docker注册表

来自分类Dev

通过PBKDF2加密的PHP MySQL PDO登录/注册系统无法登录

来自分类Dev

无法向Netflix Eureka注册Spring MicroService

来自分类Dev

Spring SockJS无法找到注册的处理程序

来自分类Dev

Quartz无法通过Spring找到交易

来自分类Dev

关于MBean的动态注册

来自分类Dev

Spring Ehcache MBean监视

来自分类Dev

IBM Worklight 6.2:JMX配置错误。无法获得MBean

来自分类Dev

使用xml spring配置为jmx mbean配置只读属性

来自分类Dev

无法通过WiFi注册SIP

来自分类Dev

无法通过XMPPFramework在Jabberd中注册新的用户帐户

来自分类Dev

无法通过注册表安装Firefox扩展

来自分类Dev

如何将spring task:executor导出为mbean?

来自分类Dev

无法通过注册器注册Docker服务

来自分类Dev

无法使用先前通过注册查询创建的哈希密码无法登录的用户

来自分类Dev

如何通过RouterFunctionMapping在Spring 5 webflux中注册多个RouterFunctions?

Related 相关文章

  1. 1

    无法通过TestFlight安装应用:注册的最大设备数量

  2. 2

    注册Oracle JDBC可诊断性MBean时出错

  3. 3

    Windows 8无法通过批处理运行注册表文件

  4. 4

    带有水豚的Selenium无法通过devise登录/注册

  5. 5

    IBM Worklight 6.2:JMX配置错误。无法获得MBean

  6. 6

    关闭Spring Boot应用程序时无法注销DataSource JMX MBean

  7. 7

    通过python更改注册表无法正常工作

  8. 8

    Spring-是否可以获取所有通过@ComponentScan注册的软件包?

  9. 9

    Spring JMX-将包中的类注册为MBean

  10. 10

    无法通过登录活动通过网络服务发送注册ID(GCM)

  11. 11

    如何使用方法getPlatformMXBean()获取注册MBean?

  12. 12

    Spring JMX-<context:mbean-server>的用途

  13. 13

    如何通过代码注册Spring ApplicationListener实现?

  14. 14

    无法通过TLS推送到私有Docker注册表

  15. 15

    通过PBKDF2加密的PHP MySQL PDO登录/注册系统无法登录

  16. 16

    无法向Netflix Eureka注册Spring MicroService

  17. 17

    Spring SockJS无法找到注册的处理程序

  18. 18

    Quartz无法通过Spring找到交易

  19. 19

    关于MBean的动态注册

  20. 20

    Spring Ehcache MBean监视

  21. 21

    IBM Worklight 6.2:JMX配置错误。无法获得MBean

  22. 22

    使用xml spring配置为jmx mbean配置只读属性

  23. 23

    无法通过WiFi注册SIP

  24. 24

    无法通过XMPPFramework在Jabberd中注册新的用户帐户

  25. 25

    无法通过注册表安装Firefox扩展

  26. 26

    如何将spring task:executor导出为mbean?

  27. 27

    无法通过注册器注册Docker服务

  28. 28

    无法使用先前通过注册查询创建的哈希密码无法登录的用户

  29. 29

    如何通过RouterFunctionMapping在Spring 5 webflux中注册多个RouterFunctions?

热门标签

归档