title: Can't Register MBean via Spring
body: <p>I am trying to export an annotated MBean using Spring. But getting the following exception (when trying to deploy on tomcat7):</p>
  
  <pre><code>javax.management.MalformedObjectNameException: Key properties cannot be empty
  </code></pre>
  
  <p>Here is my JmxTestBean class:</p>
  
  <pre><code>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();
      }
  
  }
  </code></pre>
  
  <p>And here is the relevant portion from my spring context configuration:</p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans" ...&gt;
  
      &lt;context:component-scan base-package="com.i2gether.service" /&gt;
  
      &lt;context:mbean-export /&gt;
  
      &lt;bean id="serviceLayerExporter" class="org.springframework.jmx.export.MBeanExporter"  lazy-init="false"&gt;
          &lt;!-- notice how no beans are explicitly configured here --&gt;
          &lt;property name="autodetect" value="true" /&gt;
          &lt;property name="assembler" ref="assembler" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="testBean" class="com.i2gether.service.jmx.JmxTestBean"&gt;
          &lt;property name="name" value="TEST" /&gt;
          &lt;property name="age" value="100" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="assembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"&gt;
          &lt;property name="attributeSource"&gt;
              &lt;bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>Finally, the error log looks like this:</p>
  
  <pre><code>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 [com.i2gether.service.jmx.JmxTestBean@6e6c28f7] 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 [com.i2gether.service.jmx.JmxTestBean@6e6c28f7] 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.&lt;init&gt;(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
  </code></pre>
  
  <p>Can someone please point me to what wrong I am doing?</p>