Announcement Announcement Module
Collapse
No announcement yet.
Conditional Bean Creation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Conditional Bean Creation

    I have one interface and two implementations of the interface. Example as shown below.

    public interface A{
    public void foo();
    }

    public class B implements A{
    public void foo();
    }


    public class C implements A {
    public void foo();
    }


    Now based on a certain property value instance of B or C should be created. Example if the startDate is before November 2009 B should be created else C should be created. Can I configure this in the application-context.xml and wiring will be taken care at runtime by Spring Container, very similar to factory pattern? I am a newbie to Spring.

    Thanks in advance.

  • #2
    Just my naive response:

    I haven't seen any example of this (I wouldn't like conditional logic in XML anyway).

    I would think that a factory would be the way to go. I have seen a lot of Factory beans and that pattern seems to work well, albeit it looks a little like magic to the neophyte because you provide a factory bean, not the bean itself, but not deep dark black magic.

    Comment

    Working...
    X