Forums de discussion
Using JournalArticleService in startup action component
Abhishek Suthar, modifié il y a 7 années.
Using JournalArticleService in startup action component
New Member Publications: 18 Date d'inscription: 26/06/13 Publications récentes
Hello Developers,
I have created simple startup action component using OSGI DS annotation. I want to access journal articles when liferay starts.But some how I'm not able to access journal Article service.
Please find my code below,
Getting first two system outs in logs BUT,
I'm getting nullpointer on below line,
I have created simple startup action component using OSGI DS annotation. I want to access journal articles when liferay starts.But some how I'm not able to access journal Article service.
Please find my code below,
package com.example.api;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.osgi.service.component.annotations.ReferencePolicyOption;
import com.liferay.journal.service.JournalArticleLocalService;
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.events.LifecycleEvent;
@Component(
property={"key=application.startup.events"},
service = LifecycleAction.class
)
public class StartupActionapi implements LifecycleAction {
@Override
public void processLifecycleEvent(LifecycleEvent lifecycleEvent) throws ActionException {
System.out.println("Im starting man>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.out.println("journel>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
System.out.println("+++++++++++++++++++++"+_journalArticleLocalService.getArticles().size());
}
@Reference(cardinality = ReferenceCardinality.OPTIONAL,
policy = ReferencePolicy.DYNAMIC,
policyOption = ReferencePolicyOption.GREEDY)
protected void setJournalArticleLocalService(
JournalArticleLocalService journalArticleLocalService) {
_journalArticleLocalService = journalArticleLocalService;
}
protected void unsetJournalArticleLocalService(
JournalArticleLocalService journalArticleLocalService) {
_journalArticleLocalService = null;
}
private JournalArticleLocalService _journalArticleLocalService;
}
Getting first two system outs in logs BUT,
I'm getting nullpointer on below line,
System.out.println("+++++++++++++++++++++"+_journalArticleLocalService.getArticles().size());
Eduardo P. García, modifié il y a 3 années.
RE: Using JournalArticleService in startup action component
Regular Member Publications: 157 Date d'inscription: 16/03/12 Publications récentes
Hi Abhishek,
If you want to make sure the JournalService is available when your module starts, then you shouldn't declare your dependency with the journalService as "OPTIONAL".
Regards
If you want to make sure the JournalService is available when your module starts, then you shouldn't declare your dependency with the journalService as "OPTIONAL".
Regards
Abhishek Suthar, modifié il y a 7 années.
RE: Using JournalArticleService in startup action component
New Member Publications: 18 Date d'inscription: 26/06/13 Publications récentesEduardo P. Garcia:
Hi Abhishek,
If you want to make sure the JournalService is available when your module starts, then you shouldn't declare your dependency with the journalService as "OPTIONAL".
Regards
When I change it to MANDATORY. I'm not getting first two sysouts in logs. I think bundle not even starts.
When I change to "OPTIONAL" it shows the first two sysouts and then null pointer.