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