<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Initialize and use object using @Reference of Liferay's Service Classes</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111781191" />
  <subtitle>Initialize and use object using @Reference of Liferay's Service Classes</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=111781191</id>
  <updated>2026-04-04T04:24:41Z</updated>
  <dc:date>2026-04-04T04:24:41Z</dc:date>
  <entry>
    <title>RE: Initialize and use object using @Reference of Liferay's Service Classes</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111785480" />
    <author>
      <name>Olaf Kock</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111785480</id>
    <updated>2018-12-12T13:26:26Z</updated>
    <published>2018-12-12T13:26:26Z</published>
    <summary type="html">&lt;blockquote&gt;
  &lt;div class="quote-title"&gt;Vishal Shah:&lt;/div&gt;
  &lt;div class="quote"&gt;
    &lt;div class="quote-content"&gt;
      &lt;p&gt;Previously, using Liferay's Default Service Builder classes
        using *LocalServiceUtil and *ServiceUtil in custom portlet. Now
        I want to initalise and use via @Reference.&lt;/p&gt;
      &lt;p&gt; &lt;/p&gt;
      &lt;p&gt;I am trying for this another way but object is not initalise
        and getting NULL.&lt;/p&gt; ...  &lt;p&gt;I think any missing from my side.
        I added below line in gradle :&lt;/p&gt;
      &lt;p&gt;compileOnly group: 'com.liferay', name:
        'com.liferay.knowledge.base.api', version: '5.0.11'&lt;/p&gt;
      &lt;p&gt;compileOnly group: 'com.liferay', name:
        'com.liferay.knowledge.base.service', version: '2.0.20'&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/blockquote&gt;
 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.&lt;br /&gt;
  </summary>
    <dc:creator>Olaf Kock</dc:creator>
    <dc:date>2018-12-12T13:26:26Z</dc:date>
  </entry>
  <entry>
    <title>Initialize and use object using @Reference of Liferay's Service Classes</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111781190" />
    <author>
      <name>Vishal Shah</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=111781190</id>
    <updated>2018-12-12T06:51:40Z</updated>
    <published>2018-12-12T06:51:40Z</published>
    <summary type="html">&lt;p&gt;Previously, using Liferay's Default Service Builder classes using
  *LocalServiceUtil and *ServiceUtil in custom portlet. Now I want to
  initalise and use via @Reference.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I am trying for this another way but object is not initalise and
  getting NULL.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;protected KBArticleService kbArticleService;&lt;br /&gt; protected
  KBCommentLocalService kbCommentLocalService;&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;@Reference(unbind = &amp;quot;-&amp;quot;)&lt;br /&gt; protected void
  setKBArticleService(KBArticleService kbArticleService) {&lt;br /&gt;       
   this.kbArticleService = kbArticleService;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;@Reference(unbind = &amp;quot;-&amp;quot;)&lt;br /&gt;  protected void
  setKBCommentLocalService(&lt;br /&gt;         KBCommentLocalService
  kbCommentLocalService) {&lt;/p&gt;
&lt;p&gt;        this.kbCommentLocalService = kbCommentLocalService;&lt;br /&gt;  }&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;My custome method implemented below code :&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;kbArticle = kbArticleService.addKBArticle(&lt;br /&gt;               
   portletId, parentResourceClassNameId, parentResourcePrimKey,&lt;br /&gt;   
               title, urlTitle, content, description, sourceURL,
  sections,&lt;br /&gt;                 selectedFileNames,
  serviceContext);&lt;br /&gt;  &lt;/p&gt;
&lt;p&gt;But everytime getting kbArticleService not initalise and getting
  NULLpointer exception.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;p&gt;I think any missing from my side. I added below line in gradle :&lt;/p&gt;
&lt;p&gt;compileOnly group: 'com.liferay', name:
  'com.liferay.knowledge.base.api', version: '5.0.11'&lt;/p&gt;
&lt;p&gt;compileOnly group: 'com.liferay', name:
  'com.liferay.knowledge.base.service', version: '2.0.20'&lt;/p&gt;</summary>
    <dc:creator>Vishal Shah</dc:creator>
    <dc:date>2018-12-12T06:51:40Z</dc:date>
  </entry>
</feed>
