Wednesday, March 25, 2020

AEM6 | Enable component programmatically

Problem:

An OSGi component is disabled by default, need to enable it programmatically in AEM6.x.

Solution:

Use SCR API to enable it. Sample code here:
for (Bundle bundle : bundleContext.getBundles()) {
    ComponentDescriptionDTO dto = scr.getComponentDescriptionDTO(bundle, componentName);
    if (dto != null && !scr.isComponentEnabled(dto)) {
        LOGGER.info("Component {} disabled by configuration.", dto.implementationClass);
        scr.enableComponent(dto);
    }
}
Complete code can be found here:

Use Case:

Sample use case is to enable "com.day.cq.dam.core.impl.MissingMetadataNotificationJob" component in https://helpx.adobe.com/experience-manager/6-3/assets/using/metadata-schemas.html#Definemandatorymetadata

No comments:

Post a Comment

CDN | Clearing Cloudflare cache

In order to clear Cloudflare cache automatically via code, follow below steps: 1. Develop Custom TransportHandler Develop a custom Trans...