File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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?


Groovy
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

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


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

Joined: Mar 07, 2010
Posts: 1648
    
    7

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





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

Joined: Mar 07, 2010
Posts: 1648
    
    7

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: http://aspose.com/file-tools
 
subject: conditional injection in spring