Results 1 to 2 of 2

Thread: Bean constructor parameters

  1. #1
    Join Date
    Sep 2004
    Location
    Toronto
    Posts
    1

    Default Bean constructor parameters

    Hi.
    I am using Spring for my Swing application.
    And I came across a small problem.
    I have a bean than extends JDialog class.
    Code:
      <bean id="infoDialog" class="InfoDialog" singleton="false" init-method="initUI">
        <constructor-arg index="0"><ref bean="mainWindow"/></constructor-arg>
      </bean>
    That works fine. But I need to instantiate this bean with a different constructor argument.
    Basically I need to create a dialog and pass another dialog as constructor parameter and need to do so from my code, not from a config.
    Something like this bean_factory.getBean("infoDialog", new Object[]{MyParentDialog})

    How I can do it ?

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    At the moment, application contexts are kind of static. Once you configure them (and there are plenty of option to customize configuration), you're done. Work is being done reconfiguration at runtime, but it's not part of any current release.

    You could use the FactoryBean.

    If you need to programmatically create object (requiring more code than just calling a constructor and setting a couple of properties) use the FactoryBean. It's similar to the factory pattern and you can reference it like any other bean. Your original bean will still receive a Dialog (i.e. the Dialog created by the DialogFactoryBean).

    Have you taken a look already at the Spring RCP project by the way?

    Alef

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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