Message Boards

How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

thumbnail
ali yeganeh, modified 4 Years ago.

How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
I create 2 modules using  Gradle-based Liferay projects  ( moduleA  and  moduleB )
moduleB is a dependency for moduleA
And it works correctly
I can correctly call methods of moduleB in moduleA
But when make any change in moduleB methods, changes not applied after deploy

Attachments:

thumbnail
Christoph Rabel, modified 4 Years ago.

RE: How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

Liferay Legend Posts: 1554 Join Date: 9/24/09 Recent Posts
Do you deploy module B?
How do you inject module B into module A? Or how do you instance it? Can you show a minimal example?
thumbnail
ali yeganeh, modified 4 Years ago.

RE: How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi
Yes
After the settings I sent as an attachment in the previous post, i make an ordinary object and call my method
any change in moduleB methods not applied after deploy
Module B has the same behavior as before
but after deploy, i remove modules using telnet and then redeploy modules, it will be correct!!!
thumbnail
Olaf Kock, modified 4 Years ago.

RE: How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

Liferay Legend Posts: 6403 Join Date: 9/23/08 Recent Posts
ali yeganeh:

After the settings I sent as an attachment in the previous post, i make an ordinary object and call my method
any change in moduleB methods not applied after deploy
Module B has the same behavior as before
but after deploy, i remove modules using telnet and then redeploy modules, it will be correct!!!
OSGi only will update @Reference(s) to @Component(s). If you introduce dependencies yourself, e.g. through instanciating an object, OSGi won't magically deploy (and garbage collect) a bundle as long as there are still references to it.

I'm assuming that you're instantiating the object from module B yourself. Don't do that. If you let OSGi do the dependency management, it'll automatically restart the required modules.
thumbnail
ali yeganeh, modified 4 Years ago.

RE: How to Inject OSGi Dependencies in Custom Portlets in Liferay 7.1

Regular Member Posts: 148 Join Date: 5/1/19 Recent Posts
Hi Mr. Olaf Kock
You gave the perfect answer
Thank you very much