AEM Code Snippets : OSGI Annotations – Servlet

Here, I am going to explain how to add OSGI annotations to custom servlet, the SCR annotations are deprecated in AEM 6.3, so the people who are working on AEM 6.3 must use OSGI annotations, the OSGI annotations are very simple you do not need to remember so many things while defining properties and no need to use PropertiesUtil class to read property values

Step 1: add dependencies

Step 2: import packages

Once the dependencies are added then run “mvn eclipse:eclipse” command in command prompt, finally import below packages in your class file 

Step 3: Create a servlet

Here, I am not using separate class to load configuration, if you have so many properties to configure then I would recommend you to create a separate class and load it using @Designate annotation, want to know how to use @Designate annotation then refer my other article OSGI annotations – service

In the activate method inject the configuration class and read the properties 

Once the code is deployed then go to the configuration manager and configure the page path, you should see the same thing when you hit servlet in the browser