IPojo - @Reference does not add services

One set has an IService interface implemented by the ServiceImpl class:

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

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

 @Component @Provides @Instantiate public class ServiceConsumer { @Requires private IService service; public doIt() { service.doSomething(); } } 

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

Since IService is apparently available, I would expect @Requires to introduce a good instance, but it doesn't seem to do that.

I have a feeling that I see something very obvious, but I have no idea what.

+4
source share
2 answers

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

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

+1
source

What is the name of the doIt() method?

You do not need an XML file because you use annotations.

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

 ipojo:instances ipojo:instance instance_name 

Sincerely.

0
source

Source: https://habr.com/ru/post/1387410/


All Articles