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
RE: How to implement Startup Action Hook in LIferay DXP?
Hi Team,
I have a requirement where I have to create a hook that invoke "application.startup.events" in Liferay DXP.
How I can implement such hook in Liferay DXP and what are the configuration required for the same.
Regards,
Kushagra
I have a requirement where I have to create a hook that invoke "application.startup.events" in Liferay DXP.
How I can implement such hook in Liferay DXP and what are the configuration required for the same.
Regards,
Kushagra
Kushagra Khanna:
I have a requirement where I have to create a hook that invoke "application.startup.events" in Liferay DXP.
How I can implement such hook in Liferay DXP and what are the configuration required for the same.
You'd go for a lifecycle action. Here's a sample in a module. Check the blade-sample readme for alternative properties, to change it from a login action to another lifecycle action.
import com.liferay.portal.kernel.events.ActionException;
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;import org.osgi.service.component.annotations.Component;@Component(
immediate = true,
property = {
"key=application.startup.events"
},
service = LifecycleAction.class
)
public class CustomStartupAction extends SimpleAction{ private static final Log _log = LogFactoryUtil.getLog(CustomStartupAction .class);
@Override
public void run(String[] ids) throws ActionException { _log.info("----------------------------only on startup of server -------------------------------");
}}
import com.liferay.portal.kernel.events.LifecycleAction;
import com.liferay.portal.kernel.events.SimpleAction;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;import org.osgi.service.component.annotations.Component;@Component(
immediate = true,
property = {
"key=application.startup.events"
},
service = LifecycleAction.class
)
public class CustomStartupAction extends SimpleAction{ private static final Log _log = LogFactoryUtil.getLog(CustomStartupAction .class);
@Override
public void run(String[] ids) throws ActionException { _log.info("----------------------------only on startup of server -------------------------------");
}}
An easier solution may be to use an @Activate annotated method. This will run every time the bundle starts so you get it for initial portal startup, deployment, etc.
Thank you so much
I will try this
I will try this