Initialize and use object using @Reference of Liferay's Service ClassesInitialize and use object using @Reference of Liferay's Service Classeshttps://liferay.dev/en/c/message_boards/find_thread?p_l_id=119785333&threadId=1117811912024-03-29T05:51:10Z2024-03-29T05:51:10ZRE: Initialize and use object using @Reference of Liferay's Service ClassesOlaf Kockhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1117854802018-12-12T13:26:26Z2018-12-12T13:26:26Z<blockquote>
<div class="quote-title">Vishal Shah:</div>
<div class="quote">
<div class="quote-content">
<p>Previously, using Liferay's Default Service Builder classes
using *LocalServiceUtil and *ServiceUtil in custom portlet. Now
I want to initalise and use via @Reference.</p>
<p> </p>
<p>I am trying for this another way but object is not initalise
and getting NULL.</p> ... <p>I think any missing from my side.
I added below line in gradle :</p>
<p>compileOnly group: 'com.liferay', name:
'com.liferay.knowledge.base.api', version: '5.0.11'</p>
<p>compileOnly group: 'com.liferay', name:
'com.liferay.knowledge.base.service', version: '2.0.20'</p></div></div></blockquote>
I'd expect that you don't have dependency problems, e.g. you can't fix
it through gradle. But you probably are using the @Reference in a class
that's not a @Component. @Reference needs to be within a @Component to
be initialized on deployment. Then, if your component doesn't deploy,
you'll need to worry about the dependencies.<br />
Olaf Kock2018-12-12T13:26:26ZInitialize and use object using @Reference of Liferay's Service ClassesVishal Shahhttps://liferay.dev/en/c/message_boards/find_message?p_l_id=119785333&messageId=1117811902018-12-12T06:51:40Z2018-12-12T06:51:40Z<p>Previously, using Liferay's Default Service Builder classes using
*LocalServiceUtil and *ServiceUtil in custom portlet. Now I want to
initalise and use via @Reference.</p>
<p> </p>
<p>I am trying for this another way but object is not initalise and
getting NULL.</p>
<p> </p>
<p>protected KBArticleService kbArticleService;<br /> protected
KBCommentLocalService kbCommentLocalService;</p>
<p> </p>
<p>@Reference(unbind = "-")<br /> protected void
setKBArticleService(KBArticleService kbArticleService) {<br />
this.kbArticleService = kbArticleService;<br /> }</p>
<p>@Reference(unbind = "-")<br /> protected void
setKBCommentLocalService(<br /> KBCommentLocalService
kbCommentLocalService) {</p>
<p> this.kbCommentLocalService = kbCommentLocalService;<br /> }</p>
<p> </p>
<p>My custome method implemented below code :</p>
<p> </p>
<p>kbArticle = kbArticleService.addKBArticle(<br />
portletId, parentResourceClassNameId, parentResourcePrimKey,<br />
title, urlTitle, content, description, sourceURL,
sections,<br /> selectedFileNames,
serviceContext);<br /> </p>
<p>But everytime getting kbArticleService not initalise and getting
NULLpointer exception.</p>
<p> </p>
<p>I think any missing from my side. I added below line in gradle :</p>
<p>compileOnly group: 'com.liferay', name:
'com.liferay.knowledge.base.api', version: '5.0.11'</p>
<p>compileOnly group: 'com.lifera