Expand my Community achievements bar.

SOLVED

Annotation related doubts

Avatar

Level 9

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.

1 Accepted Solution

Avatar

Correct answer by
Level 10

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

View solution in original post

3 Replies

Avatar

Level 10

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)

Avatar

Level 9

Hi All,

Thanks a lot for your reply.

Avatar

Correct answer by
Level 10

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