Announcement Announcement Module
Collapse
No announcement yet.
How to register bean with dynamic generated ObjectName Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to register bean with dynamic generated ObjectName

    Hi,

    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?

    Thanks

    ~BL

  • #2
    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).

    Joris

    Comment


    • #3
      That's awesome! Thanks, Joris.
      I would expect these approaches can be added in reference guide

      Comment

      Working...
      X