Expand my Community achievements bar.

Nomination window for the Adobe Community Advisor Program, Class of 2025, is now open!
SOLVED

Apache Sling Context Aware Configurations Override via OSGI Configuration

Avatar

Level 1

Hi, 
We are using OOTB ca-config "com.adobe.cq.wcm.core.components.config.HtmlPageItemsConfig" to load a script on our page.
But the script src is different for each environment. So, to override it through OSGI, I have tried using Apache Sling Context-Aware Configuration Override Provider: OSGi configuration. 
my Ca-config is stored as follows:

 

Screenshot 2024-11-26 at 13.33.53.png

Screenshot 2024-11-26 at 13.34.05.png

 I want override the "value" property of srcAttr and my Override provider config is as follows: 

Screenshot 2024-11-26 at 13.39.53.png

but I am unable to achieve it,
could someone help me what's need to be corrected in this case?

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @RahulGa6 
By providing an implementation of org.apache.sling.caconfig.spi.ConfigurationOverrideProvider you can provide your own overrides - if the built-in override providers do not fit your needs.

https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati... 

Example : https://github.com/wcm-io/io.wcm.caconfig.extensions/blob/master/src/main/java/io/wcm/caconfig/exten... 

https://github.com/headwirecom/sling/tree/bc84670463a87c6e9c606ba286efc7dbf4dd70c7/bundles/extension... 



Arun Patidar

View solution in original post

5 Replies

Avatar

Community Advisor

Hi,

 

I think there’s some confusion, or perhaps I misunderstood your use case. If you need to switch a script per environment, you should use run modes and environment variables, as this is a more flexible and scalable approach. Context-Aware configurations are intended for multi-tenant projects within the same environment. Please check these threads:

 

https://stackoverflow.com/questions/57067256/how-do-i-use-run-modes-with-context-aware-configuration...

https://medium.com/@toimrank/aem-run-modes-4c36b9b0068e

https://experienceleague.adobe.com/en/docs/experience-manager-cloud-service/content/implementing/usi...

 

Hope this helps



Esteban Bustamante

Avatar

Level 1

Hi Esteban,

yes, I am aware of run modes, we are using ca-configs and few ca-configs have "src" values of which are run mode specific so I am trying to override the src of ca-configs through OSGI via Apache caconfig override provider.

Avatar

Community Advisor

Avatar

Level 1

Hi @arunpatidar,

Thanks for your response!
I have tried the way you have mentioned, syntax issue is solved but I am unable to override the property.
In general if you look at any ca-config, the properties are stored under jcr:content node, but for this config it is stored in the child resources present under jcr:node, this is causing some issue in identifying the property. is there a way to point the property for such configurations?

Avatar

Correct answer by
Community Advisor

Hi @RahulGa6 
By providing an implementation of org.apache.sling.caconfig.spi.ConfigurationOverrideProvider you can provide your own overrides - if the built-in override providers do not fit your needs.

https://sling.apache.org/documentation/bundles/context-aware-configuration/context-aware-configurati... 

Example : https://github.com/wcm-io/io.wcm.caconfig.extensions/blob/master/src/main/java/io/wcm/caconfig/exten... 

https://github.com/headwirecom/sling/tree/bc84670463a87c6e9c606ba286efc7dbf4dd70c7/bundles/extension... 



Arun Patidar