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

 

 

  • Divya Garg

    I am trying to follow this , but it looks like I cannot see my service listed inside bundle unless I explicity save my osgi configuration via /system/console/configMgr. When I deploy code , osgi config configuration binding shows new or unbound configuration .Is it something to do with initializing congig object or declaring component as factory