This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conditional injection in spring

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we have conditional injection in spring like is system property value is A, inject bean A. if the value is B inject bean B. Is such a thing possible?
 
Sagar Rohankar
Ranch Hand
Posts: 2906
1
Java Spring Ubuntu
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do they implement a common interface?


You can do a number of things. If you are using java config just @Autowire in Springs Environment and return the bean you want



With XML you can do the same thing just use SPEL



Or you could use a factory bean. You can google for the XML equivalent if you are not familiar with them
http://blog.springsource.org/2011/08/09/whats-a-factorybean




 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just an additional note. My first 2 options assume the use of a PropertyPlaceholderConfigurer or if you are using spring 3.1 it should be a PropertySourcesPlaceholderConfigurer
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic