In my pre­vi­ous post (http://​blogs​.adobe​.com/​e​x​p​e​r​i​e​n​c​e​d​e​l​i​v​e​r​s​/​e​x​p​e​r​i​e​n​c​e​-​m​a​n​a​g​e​m​e​n​t​/​u​s​i​n​g​-​o​s​g​i​-​a​n​n​o​t​a​t​i​o​n​s​-​a​e​m​6​-2/) you can read on how to use OSGi R6 anno­ta­tions.

From AEM6.4 you can use the OSGi R7 anno­ta­tions, sim­i­lar like the oth­er arti­cle I will guide you through the steps you need to to do in your project on how to use this in your project.

In this online ses­sion you can find more info what is all includ­ed in OSGi R7: https://​helpx​.adobe​.com/​e​x​p​e​r​i​e​n​c​e​-​m​a​n​a​g​e​r​/​k​t​/​e​s​e​m​i​n​a​r​s​/​g​e​m​s​/​U​s​i​n​g​-​O​S​G​i​-​R​7​-​i​n​-​A​E​M​.​h​tml

Project changes

<plugin>
  <groupId>org.apache.felix</groupId>
  <artifactId>maven-bundle-plugin</artifactId>
  <version>4.1.0</version>
  <inherited>true</inherited>
</plugin>

To use the OSGi R7 anno­ta­tions, add these depen­den­cies

<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>org.osgi.service.component.annotations</artifactId>
  <version>1.4.0</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>org.osgi.annotation</artifactId>
  <version>6.0.0</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>org.osgi.service.metatype.annotations</artifactId>
  <version>1.4.0</version>
  <scope>provided</scope>
</dependency>

<dependency>
  <groupId>org.osgi</groupId>
  <artifactId>org.osgi.service.component</artifactId>
  <version>1.4.0</version>
  <scope>provided</scope>
</dependency>

You can now these anno­ta­tions in your OSGi com­po­nents:

import org.osgi.service.component.propertytypes.ServiceDescription;
import org.osgi.service.component.propertytypes.ServiceRanking;
import org.osgi.service.component.propertytypes.ServiceVendor;

@ServiceDescription("My simple service")
@ServiceRanking(1001)
@ServiceVendor("Feike")

Anoth­er thing that is pos­si­ble now is this:

@Activate 
private MyServiceConfiguration config;

This injects the con­fig direct­ly when the com­po­nent gets acti­vat­ed, so no need to do any­more via cus­tom code.

Examples

The exam­ples used, you can find here my pub­lic github.

MySim​ple​Ser​vi​ceIm​pl​.java

MySer​vice​Con​fig​u​ra​tion​.java

0 comments