File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Application Frameworks and the fly likes Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml" Watch "Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml" New topic
Author

Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml

Baalamurugan Raman
Greenhorn

Joined: Oct 29, 2004
Posts: 15
Hiya

Its exactly similar to a Factory pattern. But we dont know how to map two different Concrete implementation classes for a single Interface in application context. It goes like ...

<beans>
<bean name="intI" class="org.springframework.aop.framework.ProxyFactoryBean" >
<property name="proxyInterfaces" value="com.ejb.InterfaceI" />
<property name="target" ref="classA" />
</bean>

<bean id="classA"
class="com.ejb.ClassA">
</bean>

<bean id="classB"
class="com.ejb.ClassB">
</bean>

<beans>

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.

Thanks in advance!!


Baala
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17260
    
    6

"Baalamurugan "

Please click on the My Profile link above and change your display name to meet the JavaRanch Naming Policy of using your real first and real last names, with a space between the two.

Thanks

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Baalamurugan Raman
Greenhorn

Joined: Oct 29, 2004
Posts: 15
Hi

oh any saviour of the day to help us !!
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Not exactly sure what you're trying to do...

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.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Baalamurugan Raman
Greenhorn

Joined: Oct 29, 2004
Posts: 15
Hi

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

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Spring 2.5 : Mapping two different Class Impl for a single Interface in application-Context.xml