AEM Code Snippets : OSGI annotations – Service

Here, I am going to explain how to add OSGI annotations to custom service, the SCR annotations are deprecated in AEM 6.3, so the people who are working on AEM 6.3 must use OSGI annotations, first you need to add below dependencies

Step 1: add dependencies

Step 2: import packages

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

Step 3: create service

I have created simple FeedService interface which has only one method getFeedUrl() 

Step 4: define configuration

I am creating configuration in a separate class file which is a FeedConfiguration but, you can create an inner class for configuration

Step 5: service implementation

Using @Designate annotation you can load the FeedConfiguration, to read the configuration properties in the class file inject the FeedConfiguration in the activate method and read the properties using config instance