Expand my Community achievements bar.

SOLVED

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

Avatar

Level 4

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]";
}

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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.

EstebanBustamante_0-1691066773614.png

 



Esteban Bustamante

View solution in original post

5 Replies

Avatar

Community Advisor

According to the documentation you can use this in OSGI configurations https://experienceleague.adobe.com/docs/experience-manager-cloud-service/content/implementing/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/deploy... 



Esteban Bustamante

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.

Avatar

Correct answer by
Community Advisor

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.

EstebanBustamante_0-1691066773614.png

 



Esteban Bustamante

Avatar

Community Advisor

@Dmytro_Panchenk 

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.

 

 

Avatar

Employee Advisor

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?