2 Replies Latest reply on Aug 21, 2006 6:35 AM by Geir

    Unregistering a MBean on un-/re-deploy

    Geir Newbie

      How can I force an MBean to be unregistered on undeploy?

      I use Spring to manage my beans and it exports one of my beans as a MBean when the application is loaded. When I redeploy my application the MBean server throws an InstanceAlreadyExistsException because my MBean from the previous deployment is still alive while Spring is trying to inject a new one..

      Anyone knows a work-a-round?

      cheers,


      Geir

        • 1. Re: Unregistering a MBean on un-/re-deploy
          Heiko Rupp Master

          Why don't you just call unregisterMBean() on the MBeanServer ?
          Something like (Pseudocode)

          MbeanServer mbs = MbeanServerLocator.locateJBoss();
          ObjectName on = new ObjectName("foo:type=service");
          mbs.unregisterMBean(on);
          


          this could also be done on command line via twiddle:

          twiddle unregister "foo:type=service"
          



          • 2. Re: Unregistering a MBean on un-/re-deploy
            Geir Newbie

            Thanks! However I found another solution. It isn't really related to JBoss since I'm using Spring to manage these beans, but here goes:

            I added the following line to the "MBeanExporter" in applicationContext.xml which forces unregistration of any existing beans with the same name. (this setting probably does the same as the code you posted does)

            <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/>