RE: How to implement Startup Action Hook in LIferay DXP?

Kushagra Khanna, modified 8 Years ago. Junior Member Posts: 45 Join Date: 12/28/14 Recent Posts
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
thumbnail
Olaf Kock, modified 8 Years ago. Liferay Legend Posts: 6441 Join Date: 9/23/08 Recent Posts
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.
asif aftab, modified 5 Years ago. Regular Member Posts: 123 Join Date: 9/2/13 Recent Posts
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 -------------------------------");
        
    }}
thumbnail
David H Nebinger, modified 5 Years ago. Liferay Legend Posts: 14933 Join Date: 9/2/06 Recent Posts
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.
asif aftab, modified 5 Years ago. Regular Member Posts: 123 Join Date: 9/2/13 Recent Posts
Thank you so much
I will try this