4

In one bundle have interface IService, implemented by class ServiceImpl:

public interface IService
{
    void doSomething();
}

@Component
@Provides
@Instantiate
public class ServiceImpl implements IService
{
    public void doSomething()
    {
    }
}

In a second bundle I have another class, ServiceConsumer (a GoGo shell command; specific annotations not included), using the service provided in the first bundle:

@Component
@Provides
@Instantiate
public class ServiceConsumer
{
    @Requires
    private IService service;

    public doIt()
    {
        service.doSomething();
    }

}

When I import and start the two bundles in Felix, I can see that all my services are correctly instantiated using ipojo:instances, and that ServiceImpl provides IService. However, when doIt() is executed, service is null.

Since IService seems to be available, I would expect that @Requires inject the good instance, but it seems not to do it.

I have the feeling there's something very obvious that I'm not doing, but I have no idea what.

civilu
  • 1,042
  • 1
  • 8
  • 17
  • I'm wondering if there is a service compatibility issue here. How are the bundles arranged? Do the provider bundle and the consumer bundle both import the interface package from the same place? – Neil Bartlett Jan 03 '12 at 12:00

2 Answers2

1

Have you also created metadata.xml? please see an example here http://felix.apache.org/site/ipojo-in-10-minutes.html

afaik you can also get it generated with maven plugin see here http://felix.apache.org/site/ipojo-hello-word-maven-based-tutorial.html

qwertz1123
  • 1,173
  • 10
  • 27
0

How is called the 'doIt()' method ?

You don't need a XML file as you're using annotations.

If you have the 'arch' command installed, you can check that all instances are declared and valid:

ipojo:instances
ipojo:instance instance_name

Regards.

Taryn
  • 242,637
  • 56
  • 362
  • 405
Clement
  • 2,817
  • 1
  • 12
  • 11