Foros de discusión
Using JournalArticleService in startup action component
Abhishek Suthar, modificado hace 7 años.
Using JournalArticleService in startup action component
New Member Mensajes: 18 Fecha de incorporación: 26/06/13 Mensajes recientes
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, modificado hace 3 años.
RE: Using JournalArticleService in startup action component
Regular Member Mensajes: 157 Fecha de incorporación: 16/03/12 Mensajes recientes
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, modificado hace 7 años.
RE: Using JournalArticleService in startup action component
New Member Mensajes: 18 Fecha de incorporación: 26/06/13 Mensajes recientesEduardo 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.