Create Custom OSGi Configuration In AEM
Open Service Gateway Initiative which is OSGi is a fundamental element in the technology stack of Adobe Experience Manager (AEM) which makes it modular. OSGi provides different configurations and also we can create our own custom configuration as per requirement.
Step 1 — First of all creates an interface whose public methods will represent the fields in our configuration.
Create an interface named CustomConfig.java under.“\aem\core\src\main\java\com\demoproject\core\services\CustomConfig.java” and paste the following code into it.
Step 2 — Now Create an implementation class CustomConfigImpl.java for our interface CustomConfig as below.
Step 3 — Now create JSON file for the default values of our configuration. Create “com.demoproject.core.services.impl.CustomConfigImpl.cfg.json” under.“\aem\ui.config\src\main\content\jcr_root\apps\demoproject\osgiconfig\config\”
create a similar JSON file under different environments like
- config.dev
- config.stage
- config.prod
and update the config values as per the environments.