Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

conditional injection in spring

 
Pradeep bhatt
Ranch Hand
Posts: 8933
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: 2907
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