Overriding out of the box servlet in AEM (Sling)

Technical Context
In AEM (CQ), sevlets are defined as OSGi services implementing javax.servlet.Servlet interface. A service listener org.apache.sling.servlets.resolver.internal.SlingServletResolver  in sling framework listens for OSGi services implementing javax.servlet.Servlet interface and registers its reference. When a request hits the server, this SlingServletResolverread the rest.

Overriding out of the box servlet in AEM (Sling)

OSGi component in AEM that is active only in specific run mode (say, publish).

Scenario
Implementing an OSGi component in AEM which is active (that runs) only in specific run modes (say, publish).

Implementation
Generally, in OSGi container (Apache felix in AEM), to get a component ‘satisfied’, all the referenced services have to be … read the rest.

OSGi component in AEM that is active only in specific run mode (say, publish).