karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b..@petinou.fr
Subject How to manage several service instances with declarative services?
Date Mon, 11 Jan 2016 08:35:17 GMT
Hi everyone!

I asked a question on stackoverflow regarding the use of Declarative 
Services in Karaf to manage multiple instances of a service, provided by 
different implementations of such a service.

The question is explained in details here:


I received and answer telling me that using the @reference annotation on 
the list storing the services would solve my problem. For this, I would 
need to use DS 1.3.

I thus asked on Karaf users mailing list what was the version of Felix 
SCR provided with Karaf 4.0.3 

and was told it was Felix SCR 2.0.2, which supports DS 1.3. So far so 

I was also kindly advised to ask this kind of questions here. So here I 
am :-)

Following the answer on stackoverflow, I tried to add the @reference 
annotation to my service list like this:

@Reference(service = FileReader.class)
private List<FileReader> availableServices = new ArrayList<>();

But it does not compile: FileReaderFactory.java:[37,5] annotation type 
not applicable to this kind of declaration

My project has a dependency on:


which seems to be the latest version available.

I thus tried the "older way" by using explicit bind/unbind methods like 

     @Reference(service = FileReader.class, unbind = "removeService")
     public void addService(final FileReader serviceToAdd) {

     public void removeService(final FileReader serviceToRemove) {

If I have two implementations available, say TxtFileReader and 
XmlFileReader, only the first one is added to the list. The status of 
the second service (using scr:detail command) is "null".

What am I missing?

Kind regards,


View raw message