difference between @slingServlet vs Felix scr annotation vs OSGI DS | Community
Skip to main content
New Participant
Oct 12, 2017 7:34 PM UTC
Solved

difference between @slingServlet vs Felix scr annotation vs OSGI DS

I have been reading through the documentation and confused as to when to use @slingServlet vs Felix scr annotation vs OSGI  DS. 

In one of the tech documents i read that OSGI DS is the newer standard and should be used instead of Felix scr anotation , but I could not link the @slingServlet  ?

Are these 3 different ways of creating OSGi components ? or something else ?

When do we use @slingServlet  ?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 13, 2017 2:59 PM UTC

You basic confusion is there are two main packages that define annotations.

org.osgi.service.component.annotations.Component

org.apache.felix.scr.annotations.Component

For example, the @Component annotation used in Maven Archetype 10 was org.apache.felix.scr.annotations.Component

Now the @Component Annotation used in Maven Archetype 11 is org.osgi.service.component.annotations.Component;

There are quite a few significant changes. For example, there is no longer @Service or @SlingServlet annotations in org.osgi.service.component.annotations.

In Maven Arch 10 project - we could defined a servlet like this:

@SlingServlet(paths="/bin/mySearchServlet", methods = "POST", metatype=true)

public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {

     private static final long serialVersionUID = 2598426539166789515L;

In Maven Arch 11 – we define a servlet like this – no @SlingServlet annotation:

@Component(service=Servlet.class,

property={

Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_POST,

"sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"

           })

Read this article written by Feike:

Learn about the Annotations in the org.osgi.service.component.annotations package

4 replies

New Participant
Oct 13, 2017 4:27 PM UTC

thanks smacdonald2008​

Translate
smacdonald2008
smacdonald2008Accepted solution
Level 10
Oct 13, 2017 2:59 PM UTC

You basic confusion is there are two main packages that define annotations.

org.osgi.service.component.annotations.Component

org.apache.felix.scr.annotations.Component

For example, the @Component annotation used in Maven Archetype 10 was org.apache.felix.scr.annotations.Component

Now the @Component Annotation used in Maven Archetype 11 is org.osgi.service.component.annotations.Component;

There are quite a few significant changes. For example, there is no longer @Service or @SlingServlet annotations in org.osgi.service.component.annotations.

In Maven Arch 10 project - we could defined a servlet like this:

@SlingServlet(paths="/bin/mySearchServlet", methods = "POST", metatype=true)

public class HandleClaim extends org.apache.sling.api.servlets.SlingAllMethodsServlet {

     private static final long serialVersionUID = 2598426539166789515L;

In Maven Arch 11 – we define a servlet like this – no @SlingServlet annotation:

@Component(service=Servlet.class,

property={

Constants.SERVICE_DESCRIPTION + "=Simple Demo Servlet",

"sling.servlet.methods=" + HttpConstants.METHOD_POST,

"sling.servlet.paths="+ "/bin/myDataSourcePoolServlet"

           })

Read this article written by Feike:

Learn about the Annotations in the org.osgi.service.component.annotations package

Translate
New Participant
Oct 13, 2017 2:46 PM UTC

Hi kautuk

Thanks for your response, but I did refer to -  Nate's article before posting this message and it did clarify  some question , however I see 3 nomenclature , one for each  :

  • OSGI DS
  • Felix SCR
  • SlingServlet

I understand the relation between DS and Felix SCR, but I dont understand how SlingServlet fits in?

Translate
kautuk_sahni
Employee
Oct 13, 2017 5:56 AM UTC

I would really recommend you to read this article by Nate:- Official OSGi Declarative Services Annotations in AEM - Adobe Experience Manager | AEM/CQ | Apache Sling

~kautuk

Translate
Kautuk Sahni