Aug 24th, 2007, 09:00 PM
How to register bean with dynamic generated ObjectName
ObjectName for MBean is usually defined in xml (key) or annotation. But it seems ObjectName has to be defined statistically.
However if ObjectName has to be generated at runtime, how should I do it?
For instances, I have UserService bean (non-singleton). When multiple users log in, multiple UserService instances need to be created. ObjectName need to contains sessionId. Where and How should I define this dynamic generated ObjectName?
Sep 2nd, 2007, 04:30 PM
You can create the ObjectName yourself and then call MBeanExporter.registerManagedResource(Object managedResource, ObjectName objectName). Just inject a reference to the MBeanExporter in the object that should perform the registration.
Another option would be to make sure the sessionid becomes available to the ObjectNamingStrategy and then create an implementation of that yourself and register it with the MBeanExporter. If this is possible, I would consider that the cleanest, since your code will be completely decoupled from Spring.
Finally, you could also make your services implement SelfNaming to provide their own ObjectName (which couples your services to Spring, obviously, but it could be the simplest solution if the sessionid is available already to your services).
Sep 4th, 2007, 10:06 PM
That's awesome! Thanks, Joris.
I would expect these approaches can be added in reference guide