Forums de discussion

OSGi component reference in ServiceBuilder ServiceImpl class

thumbnail
Benjamin Bini, modifié il y a 6 années.

OSGi component reference in ServiceBuilder ServiceImpl class

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
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, modifié il y a 6 années.

RE: OSGi component reference in ServiceBuilder ServiceImpl class

Liferay Legend Publications: 14919 Date d'inscription: 02/09/06 Publications récentes
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, modifié il y a 6 années.

RE: OSGi component reference in ServiceBuilder ServiceImpl class

Junior Member Publications: 31 Date d'inscription: 24/05/13 Publications récentes
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.)