aem configuration env vars - JAVA or config files, how to combine?
Every application needs to read env specific or tuneable config parameters.
The only way to do this is OSGi configs.
Finding an end to end example of creating config variables (not via UI on a specific instance, but in code in git so it can be deployed to other envs), is difficult.
There seem to be two types of post on the subject:
- those going into the JAVA code on creating OSGi services, requiring creating, understanding and debugging hundreds, if not thousands, of lines of java code to read a hand full of variables. The problem with this approach is there is no way to set the variables before hand, and setup env specific values in git which can be deployed. e.g. this post: https://aem.redquark.org/2018/10/day-12-creating-your-custom-osgi.html
- Those tutorials who only mention config files. This seems to allow pre-creation of values for different envs, but no way to read or update them. E.g. this post: https://experienceleague.adobe.com/docs/experience-manager-65/deploying/configuring/configure-runmodes.html?lang=en#defining-configuration-properties-for-a-run-mode
I am having trouble reconciling these two. I cant find a tutorial which combines these two, or provides a way for an application to read the values if the files approach is used.
This post:
any suggestions?
Is particularly confusing, as it mentions several concepts, including:
sling.run.modes=author
{
"connection.timeout": 1000
}
But not which files (and paths) any of these are actually done in, and how an application (e.g a servlet, or a page) might read these values.
I have not yet found a way to set a config value anywhere, and read it, other than the complex route of writing a dedicated OSGi service in Java, which is a lot of work, can only be used by a single "service" java class (not several classes or globally), an doesn't have a way to do distribute env specific vars via code (only can set them manually after deployment to a specific env)
I am missing the tutorial which brings all this together.