AEM R6 Annotation 

AEM R6 annotation allow us to add configurations to OSGI Services with the help of @Designate annotation. @Designate is must to have ocd(object class definition) property to declare service name as mentioned in below syntax.

@Designate(ocd = PracticeServiceOCDConfiguration.class)

Follow below steps to create ocd configurations and consume it as part of @Component annotation services:

1. Create a configuration interface with the hep of @interface annotation and provide @ObjectClassDefinition annotation on top of the class.

Declare configuration for all the properties with the help of @AttributeDefinition annotation using name, description and type of property as shown below.

2. Create below interface named as PracticeOCDService.java having and a public method getName() and getCountries() methods.

3. Create below class PracticeOCDServiceImp.java which implements PracticeOCDService.java interface and implement getName() and getCountries() methods.

Mention @Component annotation on top of the class. Declare Service interface as part of service property and add one more property immediate=true to instantiate component immediately else declare it as false to instantiate on demand.

Mention one more @Designate annotation on top of service implementation class. Declare ocd property and assign PracticeServiceOCDConfiguration.clas as value.

Override activate method to get configuration values defined as part of OCD configuration.

4. Create one Servlet(SlingServletByPathForOCD.java) to consume above created service(PracticeOCDService.java) with the help of @Reference annotation. We are going to user servlet as part of current implementation.

5. Open System console components (http://localhost:4502/system/console/components) to verify OSGI service and Servlet successfully installation on AEM instance showing status as active.

6. Verify service and its configurations on below URL
http://localhost:4502/system/console/configMgr

7. Hit servlet URL as http://localhost:4502/bin/practice/ocd in browser to check output:

Run mode Configurations

Run mode allows us to declare environment specific properties and values.

If run mode configuration is not defined for any service, It will consider configuration values for all properties defined in java class by default.

Below is the configuration file we created for PracticeOCDServiceImp.java class.

Run mode configuration file name follows specific naming convention as <package_name>.<Service_Impl_java_class_name>.xml

e.g. com.javadoubts.core.services.impl.PracticeOCDServiceImpl.xml

Configuration File Location

Configurations created inside config folder will be available for all environments and AEM instances.

Verify service and its latest run mode configurations on below URL
http://localhost:4502/system/console/configMgr

Hit servlet URL as http://localhost:4502/bin/practice/ocd in browser to check output:

This time it will read values from config run mode configurations.

Imran Khan

Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.

  • Languages: Java, Python
  • Frameworks: J2EE, Spring, Struts 2.0, Hibernate
  • Web Technologies: React, HTML, CSS
  • Analytics: Adobe Analytics
  • Tools & Technologies: IntelliJ, JIRA

🌐 LinkedIn

📝 Blogs

📧 Imran Khan