Results 1 to 3 of 3

Thread: How to register bean with dynamic generated ObjectName

  1. #1

    Default 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. #2
    Join Date
    Mar 2005
    Location
    The Netherlands
    Posts
    121

    Default

    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

  3. #3

    Default

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •