โ๏ธ OSGi Framework in AEM Explained (Apache Felix) โ Complete Beginner Guide
Chapter 2 of AEM Learning Series โ Understanding the engine that runs AEM.
๐ What is OSGi?
OSGi = The engine that runs AEM
AEM is not a single huge Java application.
It is made of hundreds of small modules called Bundles.OSGi is the framework that:
Loads bundles
Starts bundles
Stops bundles
Connects bundles together
AEM uses the Apache Felix implementation of OSGi.
๐ฑ Smartphone Analogy
Phone OS โ OSGi Mobile Apps โ Bundles โข Install/uninstall apps without restart โข Apps talk to each other โข OS manages lifecycle๐คฏ Why AEM Uses OSGi
Without OSGi (Traditional Java App)
ONE BIG APPLICATION
Change one thing โ Redeploy everything
Restart โ 15+ min downtime ๐ฌ
With OSGi (AEM)
Bundle A (Assets)
Bundle B (Workflow)
Bundle C (Search)
Bundle D (Auth)
Bundle E (Editor)
Your Custom Bundle
๐ Update one bundle โ No restart required
This is called Hot Deployment ๐ฅ
๐งฉ Key OSGi Concepts
1๏ธโฃ Bundle (The Deployment Unit)
A Bundle = JAR file + OSGi metadata
Each bundle contains:
META-INF/MANIFEST.MF
This file tells OSGi:
Bundle name
Version
Exported packages
Imported packages
Dependencies
๐ Smallest deployable unit in AEM.
2๏ธโฃ Bundle Lifecycle
INSTALLED โ RESOLVED โ STARTING โ ACTIVE
โ
โผ
STOPPING โ UNINSTALLED
| State | Meaning |
| INSTALLED | Bundle added but dependencies not checked |
| RESOLVED | Dependencies satisfied |
| ACTIVE | Running and providing services |
| STOPPING | Shutting down |
| UNINSTALLED | Removed |
๐ก Most common AEM issue:
Bundle stuck in INSTALLED โ Missing dependencies.
3๏ธโฃ OSGi Services (Plug & Socket Model)
Service = Interface + Implementation
Interface โ Socket
Implementation โ Plug
Any bundle can request a service, and OSGi injects it automatically.
Example Code
// Interface
public interface GreetingService {
String getGreeting(String name);
}
// Implementation
@Component(service = GreetingService.class)
public class GreetingServiceImpl implements GreetingService {
public String getGreeting(String name) {
return "Hello " + name;
}
}
// Injecting in Sling Model
@Model(adaptables = Resource.class)
public class HeaderModel {
@OSGiService
private GreetingService greetingService;
}
4๏ธโฃ OSGi Configurations (No Hardcoding!)
Instead of hardcoding values:
smtp.gmail.com
Use configuration:
mail.smtp.host = smtp.gmail.com
mail.smtp.port = 587
Different environments can have different configs:
| Environment | SMTP |
| Author | smtp.internal.company.com |
| Publish | smtp.external.company.com |
๐ No code changes required.
๐ Where to See OSGi in AEM
| Console URL | Purpose |
/system/console/bundles | All bundles |
/system/console/components | All services |
/system/console/configMgr | OSGi configs |
/system/console/status-slingmodels | Sling Models |
This is called the Felix Web Console.
๐ง OSGi in AEM Architecture
AEM
โโโ OSGi (Felix)
โโโ Sling Bundles
โโโ Oak Bundles
โโโ Workflow Bundles
โโโ Your Custom Bundles
All communicate via OSGi Service Registry.
๐ Things to Remember
OSGi = modular runtime used by AEM
Bundle = deployable JAR
Service = interface + implementation
Hot deployment = no restart required
Felix Console =
/system/consoleBundle not ACTIVE? โ Dependency issue
๐ฏ AEM Interview Questions โ OSGi (30 Q&A)
๐ข Section A โ Basics
Q1. What is OSGi?
Modular Java framework used by AEM.
Q2. OSGi implementation in AEM?
Apache Felix.
Q3. Why OSGi?
Modularity โข Hot deployment โข Dependency management.
Q4. What is a Bundle?
JAR with OSGi metadata.
Q5. What is MANIFEST.MF?
Bundle metadata file.
Q6. Felix Web Console?
Admin UI at /system/console.
Q7. Default credentials?
admin/admin (dev only).
Q8. Bundles console URL?/system/console/bundles
Q9. Configurations console URL?/system/console/configMgr
Q10. Components console URL?/system/console/components
๐ต Section B โ Lifecycle
Q11. Bundle states?
Installed โ Resolved โ Active โ Stopping โ Uninstalled.
Q12. Bundle stuck in INSTALLED?
Missing dependencies.
Q13. Debug steps?
Check bundle โ imported packages โ install dependency.
Q14. ACTIVE โ RESOLVED?
Yes, when stopped or dependency removed.
Q15. Fragment bundle?
Extends another bundle.
๐ฃ Section C โ Services
Q16. OSGi Service?
Java object registered in Service Registry.
Q17. Component vs Service?
Service = component exposed via interface.
Q18. Register service annotation?@Component(service=MyInterface.class)
Q19. @Reference?
Inject service in OSGi component.
Q20. @Reference vs @OSGiService?
Component vs Sling Model injection.
Q21. Service Registry?
Runtime service lookup system.
Q22. service.ranking?
Priority for multiple implementations.
๐ Section D โ Configuration
Q23. OSGi Config?
Externalized properties.
Q24. Create configs?
Console or repository config files.
Q25. Run-mode configs?config.author, config.publish.
Q26. Factory config?
Multiple instances of same component.
Q27. PID?
Unique config identifier.
๐ด Section E โ Scenarios
Q28. Sling Model not working?
Check bundle, components, Sling Models console.
Q29. DS vs SCR?
DS = modern, SCR = deprecated.
Q30. Two bundles exporting same package?
Yes โ version resolution.
๐ Final Summary
Understanding OSGi = Understanding how AEM actually runs.
Everything you build in AEM becomes an OSGi bundle.