This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
based on the input data, I might decide Class A or Class B but with the current setup in spring we will always have only one implementation of Class ie. ClassA. There is no scope of ClassB. We struck up with on how to resolve it. Could anyone help us on this issue.
If what you're saying is - "I want two ProxyFactoryBeans, one which targets ClassA and one which targets ClassB" - then you can just create two beans with different names -
Instead if what you mean is - "I want one instance of ProxyFactoryBean, and one each of ClassA and ClassB" - take a look at this blog post about Spring instantiation strategies - especially the section titled 'Using a static factory method'.
If you mean - "I want one ProxyFactoryBean, and I want to instantiate either ClassA or ClassB at runtime" - unless this is known at startup, you won't be able to do this in a spring configuration - you'll need to make another class that can construct a ProxyFactoryBean and the class you want, and call this at runtime. If it is known at startup, you could make the class name a property, and use something like what is described in this blog post - Spring configuration with property files - the blog post isn't really about property *files* per se, but how to use a class to filter/provide properties like Spring would get from property files.
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Joined: Oct 29, 2004
Yes, You are right !! Actually I want to load the Concrete class implementation dynamically but in applicationContext.xml i can point one interface to one Class. If that is the case How can I use another implementation of class dynamically.
May be spring doesnt support us to dynamically switch two classes
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml