File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes conditional injection in spring Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "conditional injection in spring" Watch "conditional injection in spring" New topic

conditional injection in spring

Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

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

Joined: Feb 19, 2008
Posts: 2902

I'm not sure but check whether SpEL serves your problem or not:

[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Bill Gorder

Joined: Mar 07, 2010
Posts: 1649

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

[How To Ask Questions][Read before you PM me]
Bill Gorder

Joined: Mar 07, 2010
Posts: 1649

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
I agree. Here's the link:
subject: conditional injection in spring