Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Virgo » SpringDM - Exporting Spring Bean as Service - Problem with scope(<bean scope="prototype" /> does not works)
SpringDM - Exporting Spring Bean as Service - Problem with scope [message #807773] Sun, 26 February 2012 20:30 Go to next message
Eduardo Frazão is currently offline Eduardo Frazão
Messages: 118
Registered: January 2012
Senior Member
Hi all.

Im trying to export some spring beans as services, trought SpringDM Application context, and I need export them as prototypes, but it is not working. A singleton instance of the bean is created, and any bundle that makes reference get this instance.

I've read about the "bundle" scope, but this will not solve my problem, because this creates instances of services per bundle, and not by injection call as I need.

My Bean definition:

<bean id="test" class="com.xyz.impl.TestImpl" scope="prototype" />
<osgi:service ref="test" interface="com.xyz.Test" />


And how Im consuming this service on another bundle
<osgi:reference id="test" interface="com.xyz.Test" />


I've read from old post, on springsource site, when people says that is a problem with OSGi Service registry (this makes cache of services), but this post is from 2005, and they say to use some kind of proxy as workaround. Is this the unique way?

Thanks by any help!

[Updated on: Mon, 27 February 2012 06:09]

Report message to a moderator

Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #807834 is a reply to message #807773] Sun, 26 February 2012 22:56 Go to previous messageGo to next message
karthik elavan is currently offline karthik elavan
Messages: 70
Registered: August 2011
Location: Chennai
Member
Hi,
I have facing this problem so given sample osgi bean config, try this one.

web project bundle contest osgi .xml sample:


<bean id="testServicecall"
class="com.osgi.middletiercore.service.impl.osgiServiceCall"
scope="prototype" autowire="byName">
<property name="osgiinterface">
<bean class="com.osgi.middletiercore.service.impl.xxxx" />
</property>
</bean>

<bean id="testServiceCall"
class="com.osgi.middletiercore.service.impl.osgiServiceCall"
scope="prototype" />

dmservice-osgi.xml :

<osgi:service id="complexServiceCallOsgi" ref="complexServiceCall" interface="com.osgi.middletiercore.service.IServiceCall" />
<osgi:service id="simpleServiceCallOsgi" ref="testServiceCall" interface="com.osgi.middletiercore.service.IServiceCall" />


dmservice.xml :

<bean id="testServicecall"
class="com.osgi.middletiercore.service.impl.osgiServiceCall"
scope="prototype" autowire="byName">
<property name="osgiinterface">
<bean class="com.osgi.middletiercore.service.impl.xxxx" />
</property>
</bean>

<bean id="testServiceCall"
class="com.osgi.middletiercore.service.impl.osgiServiceCall"
scope="prototype" />
</beans>

All the best .....

[Updated on: Sun, 26 February 2012 22:57]

Report message to a moderator

Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #808078 is a reply to message #807834] Mon, 27 February 2012 06:20 Go to previous messageGo to next message
Eduardo Frazão is currently offline Eduardo Frazão
Messages: 118
Registered: January 2012
Senior Member
Hi karthik elavan! Thanks by your help!

Only to clarify:

You have an a general interface for Beans exporting services:

-- IServiceCall

This interface haves an getOsgiInterface method that encapsulates the Service real implementation right?

So, you export all your beans as IServiceCall?

On the other side, how you get a reference to the service? Do you pass some filter to get the right implementation, and inject it onto your components?

By this way, the prototype implementation works?

Sorry if I missundertood your example.
Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #808234 is a reply to message #807773] Mon, 27 February 2012 10:08 Go to previous messageGo to next message
Eduardo Frazão is currently offline Eduardo Frazão
Messages: 118
Registered: January 2012
Senior Member
Doing some resarch about this problem, I found this thread:

http://markmail.org/message/pdiiktxsack5ahp2#query:+page:1+mid:r73w6nw6t2jaru7d+state:results

Where this problem is reported, and a solution is propoused. (even with a patch)

Latter, on SpringSource, a bug was opened to solve this problem, it appears to be with no activity:

https://jira.springsource.org/browse/OSGI-237

For this reason, i've opened a bug on Virgo too:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=372650

Thanks!

[Updated on: Mon, 27 February 2012 11:28]

Report message to a moderator

Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #808665 is a reply to message #807773] Mon, 27 February 2012 20:57 Go to previous messageGo to next message
Dmitry Sklyut is currently offline Dmitry Sklyut
Messages: 271
Registered: January 2010
Senior Member
You could actually register a service with ServiceFactory and use that as a prototype generator.

Take a look in SpringDM docs

Hope this helps

Dmitry
Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #808998 is a reply to message #808665] Tue, 28 February 2012 06:13 Go to previous message
Eduardo Frazão is currently offline Eduardo Frazão
Messages: 118
Registered: January 2012
Senior Member
Hi Dmitry!! First of all, thank by your answer.!
But, according to the Docs, the ServiceFactory will return an instance per bundleContext.getService() right? In this case, I will have an instance per bundle, like the scope="bundle" right?

Im my scenario, I will need an instance per injection call, or even better, one instance per "HttpSesssion", when services will be consumed by an action fired by a web request. (95% of the time).

But, according to this post: http://www.eclipse.org/forums/index.php/mv/msg/269120/770471/#msg_770471

I can solve my problem with the session and prototype beans. In the case of the prototype, I have an instance per call, insted of one instance per injection call (this is was I have opened the bug), but for now, it is enought, and with this workaround I can continue my work!!!

I hope that this thread can help other people with the same issue!!
Previous Topic:Snaps issues with dispatchservlet mapped to (snap) root and separate resources folder
Next Topic:Advice on solution architecture needed
Goto Forum:
  


Current Time: Wed Jul 30 21:20:28 EDT 2014

Powered by FUDForum. Page generated in 0.01645 seconds