Creating a Listener in AEM: The Recommended Way

Problem statement:

What is the Adobe Experience Manager recommended way to create a Listener?


Adobe provides a Framework service registry that allows EventHandler objects to be registered and notified when an event is sent or posted. This article explains the recommended way to create a Listener to handle events on the property in Adobe.


  • EventHandler objects are registered with the Framework service registry and are notified with an Event object when an event is sent or posted.
  • EventHandler objects can inspect the received Event object to determine its topic and properties.
  • EventHandler objects must be registered with a service property EventConstants.EVENT_TOPIC whose value is the list of topics in which the event handler is interested.


Create Component Service with Event Handler class and implement Event Handler class Provide event topic for the action

Override handle event method

package com.mysite.core.listeners;

import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.propertytypes.ServiceDescription;
import org.osgi.service.event.Event;
import org.osgi.service.event.EventConstants;
import org.osgi.service.event.EventHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(service = EventHandler.class,
           immediate = true,
           property = {
                   EventConstants.EVENT_TOPIC + "=org/apache/sling/api/resource/Resource/*"
@ServiceDescription("Demo to listen on changes in the resource tree")
public class SimpleResourceListener implements EventHandler {

    private final Logger logger = LoggerFactory.getLogger(getClass());

    public void handleEvent(final Event event) {
        logger.debug("Resource event: {} at: {}", event.getTopic(), event.getProperty(SlingConstants.PROPERTY_PATH));

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s