How to read different environment Config properties in you java code ?

Avatar

Avatar

NaziyaP

Avatar

NaziyaP

NaziyaP

19-06-2019

Hi All,
I have been following Adobe Experience Manager Help | Reading Adobe Experience Manager OSGi Configuration Values  for reading properties in my code.
When i runt he sample provided it runs fine and gives correct output but when i integrate the same nodes and classes in my project, my service doesn't get registered on activation of bundle.

Since this sample uses the deprecated felix annotations i tried modifying it to current standards , now my service is registers but the activate method is never called.

I also saw one acs sample code on github SampleOsgiR6AnnotationsImpl.java but unable to understands if it is related to my requirement, since i dont see any connection with osgiConfig node.

What i need is able to read properties based on different run modes in my java file on bundle activation.
Can anyone please suggest for the same.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K

Avatar

Jörg_Hoh

Employee

Total Posts

3.0K

Likes

916

Correct Answer

1.0K
Jörg_Hoh
Employee

19-06-2019

The handling and injection of of OSGI properties, including the correct matching of runmodes should be left the framework. And from my point of view there is never a reason to bypass this. If you do, you are violating AEM best practices.

And if you really need to read the configuration for other environments (because otherwise the framework would it inject for you), something is wrong. Most likely you are using OSGI properties for a purpose they are not intended for.

Jörg

Answers (2)

Answers (2)

Avatar

Avatar

akashk22786878

Employee

Avatar

akashk22786878

Employee

akashk22786878
Employee

19-06-2019

Hi,

Seems you want to use the osgi configs per the run mode. It is usually picked in the AEM instance based on its runmode only. You can refer to public blogs like http://aempodcast.com/2016/apache-sling/demonstrate-slingosgiconfig-runmodes/#.XQo3npgzaUk  to get more details.

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831

Avatar

Arun_Patidar

MVP

Total Posts

2.9K

Likes

1.0K

Correct Answer

831
Arun_Patidar
MVP

19-06-2019

Hi,

Please check for sample osgi service and how to call from servlet.

AEM6.4 @Reference not working in SlingServlet

and for reading osgi config without service

AEM osgiconfig node for different profile.