Foros de discusión

OSGi component reference in ServiceBuilder ServiceImpl class

thumbnail
Benjamin Bini, modificado hace 6 años.

OSGi component reference in ServiceBuilder ServiceImpl class

Junior Member Mensajes: 31 Fecha de incorporación: 24/05/13 Mensajes recientes
Hi guys, I have a question about OSGi and ServiceBuilder.

I have an OSGI component loaded called "AdictService", I want to use it from an XXXServiceImpl class from a ServiceBuilder module.
I try to reference it using @Reference but it does not work and my AdictService reference remains null in the ServiceImpl class
If I reference it in a portlet, which is a "@Component", it works.

What can I do to be able to get a reference to my OSGi service in my ServicBuilder ServiceImpl class ?

Thanks
thumbnail
David H Nebinger, modificado hace 6 años.

RE: OSGi component reference in ServiceBuilder ServiceImpl class

Liferay Legend Mensajes: 14916 Fecha de incorporación: 2/09/06 Mensajes recientes
You really can't. Spring context and OSGi context are two different things. Liferay, through its magic, exposes spring beans as OSGi services, but that is not done by default.

To access an OSGi service in a non-OSGi context, the ServiceTracker is your friend.
thumbnail
Benjamin Bini, modificado hace 6 años.

RE: OSGi component reference in ServiceBuilder ServiceImpl class

Junior Member Mensajes: 31 Fecha de incorporación: 24/05/13 Mensajes recientes
Ok I now understand why it did not work, I did not think about the OSGi context / Spring context difference.

Thank you very much, the ServiceTracker strategy works as expected, except that "PostConstruct" and "PreDestroy" do not seem to be called for my ServiceImpl class. I use a workaround for now but if you have any idea about why I am all ears!

(By the way it was really nice speaking to you at the DevCon, hope we'll see you there next year too.)