In my previous post (http://blogs.adobe.com/experiencedelivers/experience-management/using-osgi-annotations-aem6-2/) you can read on how to use OSGi R6 annotations.
From AEM6.4 you can use the OSGi R7 annotations, similar like the other article 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 session you can find more info what is all included in OSGi R7: https://helpx.adobe.com/experience-manager/kt/eseminars/gems/Using-OSGi-R7-in-AEM.html
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 annotations, add these dependencies
<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 annotations in your OSGi components:
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")
Another thing that is possible now is this:
@Activate private MyServiceConfiguration config;
This injects the config directly when the component gets activated, so no need to do anymore via custom code.
Examples
The examples used, you can find here my public github.
The post Using OSGi R7 annotations in AEM appeared first on Experience Delivers.