IPojo - @Reference 不注入服务
在一个包中有接口 IService,由 ServiceImpl 类实现:
public interface IService
{
void doSomething();
}
@Component
@Provides
@Instantiate
public class ServiceImpl implements IService
{
public void doSomething()
{
}
}
在第二个包中,我有另一个类 ServiceConsumer(一个 GoGo shell 命令;不包括特定注释),使用第一个包中提供的服务:
@Component
@Provides
@Instantiate
public class ServiceConsumer
{
@Requires
private IService service;
public doIt()
{
service.doSomething();
}
}
当我导入并启动两个包时在 Felix 中的捆绑包中,我可以看到我的所有服务都使用 ipojo:instances 正确实例化,并且 ServiceImpl 提供 IService。然而,当执行 doIt() 时,service 为 null。
由于 IService 似乎可用,我希望 @Requires 注入好的实例,但似乎没有这样做。
我感觉有一些很明显我没有做的事情,但我不知道是什么。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否还创建了metadata.xml?
请参阅此处的示例 http://felix.apache.org/site/ ipojo-in-10-minutes.html
afaik 你也可以使用 maven 插件生成它
请参阅此处 http://felix.apache.org/site /ipojo-hello-word-maven-based-tutorial.html
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
如何调用“
doIt()
”方法?您不需要 XML 文件,因为您使用的是注释。
如果您安装了“arch”命令,您可以检查所有实例是否已声明且有效:
此致。
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:
Regards.