AEM OSGI Services

AEM OSGI services stands for Open Service Gateway initiative. It is a java class that can register as an OSGI service.

We can create OSGI service with the help of @Component annotation from org.osgi.service.component.annotations package and register it as an OSGI service.

Deployed component on AEM instance gets handle by SCR (Sling Component Runtime). Bundles communicate with each other with the help of services.

Please follow below steps to create an OSGI service with the help of @Component annotation. Services can be consume using @Reference annotation in Servlet and other services. User @OSGiService annotation to inject service in sling model.

1. As part of current implementation, we will be making changes to below highlighted files and folders. 

2. Create below interface named as PracticeService.java and a public method getName()

3. Create below class PracticeServiceImp.java which implements PracticeService.java interface and implement getName() method at the same time as shown below. 

Service property is require to register component as service.

4. As discussed above, we are going to consume service inside servlet with the help of @Reference component. 

5. Let’s deploy code using below command as we made only Java related changes.
 mvn clean install -PautoInstallBundle

6. Open System console components to verify OSGI service installation on AEM instance showing status as active.

7. Hit servlet URL as http://localhost:4502/content/practice/us/en/_jcr_content.txt in browser to check output:

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