• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

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

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!!
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Baalamurugan Raman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

oh any saviour of the day to help us !!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Baalamurugan Raman
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic