Announcement Announcement Module
Collapse
No announcement yet.
BeanFactory and runtime arguments? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • BeanFactory and runtime arguments?

    I have a need to provide an argument to the bean producing FactoryBean while getting a reference to an object from the BeanFactory?

    so I have a need to do this

    Code:
    Object [] args;
    
    :
    :
    :
    
    beanFactory.getBean ("beanName", args);
    Is there a way to do it? If not is there a good
    reason why it can't be done?

  • #2
    I'm not clear on what you're trying to do. If you're trying to set properties of a bean based on runtime parameters, take a look at PropertyPlaceholderConfigurer.

    Comment


    • #3
      PropertyPlaceholderConfigurer is still static at runtime.

      Let me describe the situation, maybe it will become clearer.

      I am creating an Eclipse RCP application. The way Eclipse widgets work, is if you are creating one, a parent has to be supplied. I am trying to create an EclipseFormFactoryBean, that will take its parameters from spring config. The client that needs to display the form will have to make a call
      Code:
      beanFactory.getBean ("myEcliseFormFactoryBean");
      Now this will not work of course since if I want to create a form with the widgets on it in Eclipse I have to supply the parent to each of the widgets. Hence the call has to look something like:
      Code:
      beanFactory.getBean ("myEcliseFormFactoryBean", new Object [] {parent});
      an array there since in actuality you need more parameters to create an Eclipse form, parent is just one of them that is not too complicated to explain.

      Now a work around would be to create a factory that creates the configuration rather then the form first and then call some special method to actually create the form, but this is a workaround I thought maybe there is a solution?

      Now that I am thinking about it, I am realizing that bean factory supports Singleton and Prototype and the situation above is sort of a Prototype but with a little twist, since not all the prototypes are exact copies of each other and you really can not settle the differences afterwards, you have to do it while creating a prototype.

      Comment


      • #4
        If your call to beanFactory.getBean("myEcliseFormFactoryBean") is encapsulated within one method that others use to get the bean, you have a single point of control. So you can customize the prototype bean before returning it to the caller. This doesn't require any Spring features at all, but of course, it only works if you don't make direct calls to the BeanFactory throughout your app. (A good idea in any case so you minimize dependencies on the Spring API.)

        Comment

        Working...
        X