Annotation related doubts | Community
Skip to main content
New Participant
October 16, 2015
Solved

Annotation related doubts

  • October 16, 2015
  • 3 replies
  • 815 views

Hi All,

@Service, @Reference, @Properties, @component.

Have encountered the above four at various places, but was not able to get a good understanding on the same.

Can some one please explain these, with short snippet of code.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Lokesh_Shivalingaiah

Just to explain in simple terms,

@component - to mention the class as a component which will follow the component lifecycle of activate and deactivate

@service - to mention that the OSGi component is a Service which can be exposed to others to use this service

@properties - to mention the properties of a service which can be configured

@reference - to create a dependency reference of another service within a service

3 replies

smacdonald2008
New Participant
October 16, 2015

Here is where you can find theory on these annotations:

http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html

Read these community articles - they are used in them and you can build services that use them:

1 - https://helpx.adobe.com/experience-manager/using/first-osgi.html (uses  @Service and @Component)

2 - https://helpx.adobe.com/experience-manager/using/datasourcepool.html (uses the @Reference annotation to inject a DataSourcePool into the new AEM service)

3 - https://helpx.adobe.com/experience-manager/using/creating-custom-cq-tree.html (uses the @Properties annotation)

4 - https://helpx.adobe.com/experience-manager/using/damhandler.html (another example of using the @Properties annotation)

askdctmAuthor
New Participant
October 16, 2015

Hi All,

Thanks a lot for your reply.

Lokesh_Shivalingaiah
Lokesh_ShivalingaiahAccepted solution
New Participant
October 16, 2015

Just to explain in simple terms,

@component - to mention the class as a component which will follow the component lifecycle of activate and deactivate

@service - to mention that the OSGi component is a Service which can be exposed to others to use this service

@properties - to mention the properties of a service which can be configured

@reference - to create a dependency reference of another service within a service