Here are some common issue statements said by AEM developers.
- Some developers said that during component activation configuration values are not getting applied firs time.
- Some developers said that their OSGi component is not working for the first time and after that, it is working fine.
- Some developers said that we are adding log message in @Activate method having @Modified annotation as well and the first time I am getting two log messages print in my log file. After that, I am getting one log message.
- Some developers say that-
Here is the reason for all of these issues-
OSGi components got installed first and activated before activation of these OCD configurations. So that @Activate method got called before the population of OCD configuration with default values. That’s why OSGi component found null or blank values for the first time.
The actual process of these OCD configurations activation is – First they got installed and activated and they got modified with default values. So if you add a log message in a method having @Activate and @Modified annotation than when the code got deployed you will see 2 log messages in the log file for the first time only. one for activation and second for modified event.
So if you want to do some configuration at the time of activation it will be triggered with empty or null values.
What is the best way to deal with it?
In place of @Activate annotation only use @Modified annotation on your method and build the code. Then you will see your method will work fine.
What if I want to perform a one-time activity at the time of code installation?
In this case, the developer can use normal java practice and can add a flag with true or false values. For the first time keep its value as false and once the @Modified method runs for the first time change it’s value to true and for next time check this flag value and don’t perform the same activity for next time.
No comments:
Post a Comment
If you have any doubts or questions, please let us know.