Announcement Announcement Module
Collapse
No announcement yet.
getBean(String, Object[]) not defined on BeanFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • getBean(String, Object[]) not defined on BeanFactory

    Does anyone know why getBean(String, Object[]) is not defined on the BeanFactory interface? To access that method today requires a cast to AbstractBeanFactory.

    I have arguments I would like to pass to a FactoryBean for prototype creation.

    Thanks,
    Jonathan

  • #2
    See:
    http://forum.springframework.org/showthread.php?t=16900
    http://forum.springframework.org/showthread.php?t=16163

    But I find it not the standard way of using Spring. My beans are created with Spring but most of them don`t depend on Spring. So what are you trying to do?
    Last edited by robyn; May 15th, 2006, 05:58 PM.

    Comment


    • #3
      Essentially, I need to pass the bean (which is a FactoryBean) a user handle which I only have at runtime. It needs this information to create a stateful client stub. Yes, stateful... admittedly, it's awful, but we are trying to rework certain parts of an old app, and this part isn't currently fixable.

      Right now, I'm storing a singleton FactoryBean object which returns prototypes, subclassing FactoryBean with a custom interface that adds a getObject(User) method to it. So I have a helper that gets a reference to the FactoryBean itself, then casts it to a CustomFactoryBean, then calls getObject(User).

      I didn't even realize that there was a beanFactory.getBean(String, Object[]) method on AbstractBeanFactory until after I wrote the custom code above, since I was only referencing the interfaces in my design. I imagine that the cast is a much better way to go instead of the way I was trying to do it.

      So, I could do the cast, but I have to ask why this method isn't defined in any of the interfaces. It seems like it would make sense and that the person who wrote the code clearly made the provision for passing arguments to the bean in the prototype case. So why is it so inaccessible?

      Jonathan

      Comment


      • #4
        The method should actually fail if you try to use it with a FactoryBean. The args param is only supposed to be used with factory methods for creating prototypes, and if you go into the code, you'll see that this is actually verified and an exception is thrown in other cases.

        That said, you can try adding an enhancement request in Jira for this to be exposed. As has this mentioned, this is not incredibly clean, so I'm of mixed feelings as to whether it should be made generally available, but Juergen could perhaps be conviced...

        Comment

        Working...
        X