Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Initialize and use object using @Reference of Liferay's Service Classes
Previously, using Liferay's Default Service Builder classes using *LocalServiceUtil and *ServiceUtil in custom portlet. Now I want to initalise and use via @Reference.
I am trying for this another way but object is not initalise and getting NULL.
protected KBArticleService kbArticleService;
protected
KBCommentLocalService kbCommentLocalService;
@Reference(unbind = "-")
protected void
setKBArticleService(KBArticleService kbArticleService) {
this.kbArticleService = kbArticleService;
}
@Reference(unbind = "-")
protected void
setKBCommentLocalService(
KBCommentLocalService
kbCommentLocalService) {
this.kbCommentLocalService = kbCommentLocalService;
}
My custome method implemented below code :
kbArticle = kbArticleService.addKBArticle(
portletId, parentResourceClassNameId, parentResourcePrimKey,
title, urlTitle, content, description, sourceURL,
sections,
selectedFileNames,
serviceContext);
But everytime getting kbArticleService not initalise and getting NULLpointer exception.
I think any missing from my side. I added below line in gradle :
compileOnly group: 'com.liferay', name: 'com.liferay.knowledge.base.api', version: '5.0.11'
compileOnly group: 'com.liferay', name: 'com.liferay.knowledge.base.service', version: '2.0.20'
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.Vishal Shah:Previously, using Liferay's Default Service Builder classes using *LocalServiceUtil and *ServiceUtil in custom portlet. Now I want to initalise and use via @Reference.
I am trying for this another way but object is not initalise and getting NULL.
...I think any missing from my side. I added below line in gradle :
compileOnly group: 'com.liferay', name: 'com.liferay.knowledge.base.api', version: '5.0.11'
compileOnly group: 'com.liferay', name: 'com.liferay.knowledge.base.service', version: '2.0.20'