• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

conditional injection in spring

 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2908
1
Spring Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure but check whether SpEL serves your problem or not: http://static.springsource.org/spring/docs/3.0.x/reference/expressions.html
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic