tree: 28ebc720a09ddfe1d33b51a35d6bdb27169c5bc3 [path history] [tgz]
  1. karaf-scr-example-api/
  2. karaf-scr-example-client/
  3. karaf-scr-example-features/
  4. karaf-scr-example-provider/
  5. pom.xml
  6. README.md
examples/karaf-scr-example/README.md

Apache Karaf SCR example

Abstract

SCR (Service Component Runtime) is a convenient way to use services with annotations.

As it‘s part of the OSGi compendium specification, you don’t need any large dependency to use it.

Artifacts

  • karaf-ds-example-api provides the BookingService interface and Booking POJO.
  • karaf-ds-example-provider implements and exposes a BookingService using Component annotations.
  • karaf-ds-example-client uses a BookingService reference injected thanks to Reference annotations.
  • karaf-ds-example-features contains a Karaf features repository used for the deployment.

## Build

Simply use Apache Maven:

mvn clean install

## Features and Deployment

On a running Karaf instance, you register the example features repository with:

karaf@root()> feature:repo-add mvn:org.apache.karaf.examples/karaf-scr-example-features/LATEST/xml

Then, you can install the karaf-scr-example-client feature:

karaf@root()> feature:install karaf-scr-example-client

This feature installs the karaf-scr-example-provider feature providing the service, and the client bundle.

Usage

When you install the client feature, you should see on the console:

karaf@root()>                                                                                                                                                                                     
-----------
1 - AF520 - John Doe

-----------
2 - AF59 - Alan Parker