SpringDM - Exporting Spring Bean as Service - Problem with scope [message #807773] |
Mon, 27 February 2012 01:30 |
Eduardo Frazão Messages: 123 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 11:09] Report message to a moderator
|
|
|
Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #807834 is a reply to message #807773] |
Mon, 27 February 2012 03:56 |
|
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: Mon, 27 February 2012 03:57] Report message to a moderator
|
|
|
|
|
|
Re: SpringDM - Exporting Spring Bean as Service - Problem with scope [message #808998 is a reply to message #808665] |
Tue, 28 February 2012 11:13 |
Eduardo Frazão Messages: 123 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!!
|
|
|
Powered by
FUDForum. Page generated in 0.06278 seconds