• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Parent and child relationship configuration in spring?

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say we have following class definition

public Class MyClass1{

private ParentClass1 parentInstance;

public MyClass1(ParentClass1 instance)
{
this.parentInstance=instance;

}

}
Now we have five child class which extends ParentClass1. Now in spring when are composing MyClass1 ,how we will determine which child instance out of five needs to be injected here (as it depends upon some runtime parameter depending on which we have to create child instance). Please help me here how we create the configuration file i.e spring-config.xml for above scenario(i mean is there any way to configure such type of scenarios in spring)?
 
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This simple enough if you know how to create and define bean definition in your configuration file. Simply you just define all child class that you have and inject in the parent bean that you created with i.e "<constructor-arg ref="childClass1"/>".

From "MyClass1" you need to declare all child class reference variable and pass all ref variable in the constructor public MyClass1() similar what you already did.

Start from there and show us what you've done, I'll walk you through from there. Feel free post any question that you might have...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic