Search code examples
javaeclipseosgi

Declarative Service bind-Method not found


I want to use a declarative service, but an error is thrown that the bind method ist not accesible or not found:

!MESSAGE [SCR] ComponentReference.bind(): bind method 'setAreaManagment' is not found or it is not accessible!

I can't find my mistake. Here is my service interface:

IManagmentService

public interface IAreaManagmentService {
    SurfacePolygon getAreaByDatabaseID(int id);

    void setAreaVisibility(int databaseId, boolean visible);

    public void addArea(Integer objectId, Integer databaseId, double biggestLat, double biggestLon, double smallestLat,
            double smallestLon, String name, Date date);

    void removeAllAreas();

    public LinkedList<DisplayedArea> getAreas();
}

A class called GlobeView (extends ViewPart) implements this interface.

Here is the XML-File where the service is 'published'

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="visualization-servcieprovider">
   <implementation class="GlobeView"/>
   <service>
      <provide interface="IAreaManagmentService"/>
   </service>
</scr:component>

And this is the XML-File where the service should be bound:

<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" name="visualization-detailsview">
   <implementation class="DetailsView"/>
   <reference bind="setAreaManagment" cardinality="1..1" interface="IAreaManagmentService" name="IAreaManagmentService" policy="dynamic" unbind="unsetAreaManagment"/>
</scr:component>

These two methods are in the DetailsView.java

  public void setAreaManagment(IAreaManagmentService areaManagment) {
        System.out.println("AreaManagmentSet");

        this.areaManagment = areaManagment;

        System.out.println("WAS SET " + this.areaManagment);
    }

    public void unsetAreaManagment(IAreaManagmentService areaManagmentIn) {
        System.out.println("AreaManagmentUnSet");
        this.areaManagment = null;
    }

(and there is a private IAreaManagmentService areaMangment of course ;-) )

Where is my mistake? I read the fab tutorial from Lars Vogella, but I can't find my mistake

Edit: I added Service-Component: OSGI-INF/serviceprovider.xml, OSGI-INF/managmentConsumer.xml to my Manifest as well


Solution

  • Two things that might be the issue:

    1) Make sure your OSGI-INF folder is on the build path by selecting it in the build tab of the manifest editor.

    2) Add these attributes to both of your services activate="activate" immediate="true" that forces the bundle to activate.

    3) Another tip would be to remove the policy from dynamic to "static" and I bet that will solve your problem. - Duncan

    P.S The other thing I don't see is a fully qualified class name your implementation classes.