Reference environment variables in @ObjectClassDefinition default values - is it possible? | Community
Skip to main content
DmytroPanchenk
Level 3
August 2, 2023
Solved

Reference environment variables in @ObjectClassDefinition default values - is it possible?

  • August 2, 2023
  • 3 replies
  • 1385 views

Colleagues,

 

Is it possible to use environment-specific variables in @ObjectClassDefinition's default values, such as in the code fragment below?

I tried it and it didn't work but maybe I am using incorrect notation.

 

@ObjectClassDefinition(name="Runmode Example Service") public @interface Config { @AttributeDefinition(name = "User Name") String userName() default "$[env:INTEGRATION_USERNAME;default=dmytro@mape.com]"; @AttributeDefinition(name = "Password") String password() default "$[secret:INTEGRATION_PASSWORD]"; }

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by EstebanBustamante

Yeah, that won't work in Java, in the first link I posted previously you can find the places where the variables can be used.

 

3 replies

EstebanBustamante
Community Advisor and Adobe Champion
Community Advisor and Adobe Champion
August 2, 2023

According to the documentation you can use this in OSGI configurations https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/using-cloud-manager/environment-variables.html?lang=en#using.

 

That being said, you could let the default value empty in the JAVA class and the value through the OSGI config instead, something like this:

 

{ "userName" : "$[env:my_username_var]" "password": "$[env:my_pass_var]" }

 

Reference: 
https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/deploying/configuring-osgi.html?lang=en#configuration-examples 

Esteban Bustamante
DmytroPanchenk
Level 3
August 2, 2023

Hi @estebanbustamante ,

 

That notation ${env.VARIABLE_NAME} is for XML config files. I tried using that in the Java code and it didn't work.

Does it work in someone's code?

 


@estebanbustamante wrote:

That being said, you could let the default value empty in the JAVA class and the value through the OSGI config instead, something like this:

Yes, that's the proper way to do it. I am just getting ready for a training and want to explore all the possible options.

EstebanBustamante
Community Advisor and Adobe Champion
EstebanBustamanteCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
August 3, 2023

Yeah, that won't work in Java, in the first link I posted previously you can find the places where the variables can be used.

 

Esteban Bustamante
VeenaVikraman
Community Advisor
Community Advisor
August 3, 2023

@dmytropanchenk 

This syntax won't work in the Java Code. You don't need it in the Java code unless you haven't created the config files under the osgiconfig node within your projects. If the config files are not available, then only the default value from the Java code will be picked up. In that case, you can simply provide the default value using a constant or directly. There is no other way.

 

 

joerghoh
Adobe Employee
Adobe Employee
August 5, 2023

What is the symptom? any error message during the build? What's the output in the target/OSGI-INF/*.xml files for the relevant class?