【问题标题】:How to inject osgi service with felix scr annotations如何使用 felix scr 注释注入 osgi 服务
【发布时间】:2015-08-28 07:00:56
【问题描述】:

我在 felix contanier 中有一个 osgi 包,用于导出服务

@Component(label= "App Service",
    description = "App Service",
    immediate = true, enabled = true, metatype=true)
@Service(AppServiceImpl.class)
public class AppServiceImpl implements AppService {
}

在 Web 控制台中,我看到该服务正常启动。

然后我想用@Reference felix scr 注释在其他包中注入它。我知道应该有一些注射器,但找不到。

【问题讨论】:

  • 您通常可以使用@Reference 注解将此服务注入到另一个OSGI 服务(或Servlet)中。据我所知。你不需要注射。

标签: osgi


【解决方案1】:

您是否正在运行 Felix SCR 捆绑包?它是“注入器”,因为它处理由组装您的包的​​工具从这些注释生成的 XML。

【讨论】:

  • 我在这里找不到这个捆绑包felix.apache.org/downloads.cgi。我可以从哪里下载这个捆绑包?
  • 我的 felix 中有 org.apache.felix.scr-1.8.2.jar 这个包。你是这个意思吗?
  • 是的。我认为现在有更高版本。
【解决方案2】:

如果您使用 maven,请确保您的 pom.xml 中有以下说明:<_dsannotations>*</_dsannotations> 没有它,SCR 注释将无法工作。

【讨论】:

    猜你喜欢
    • 2018-04-27
    • 2017-12-19
    • 2010-10-02
    • 2011-10-15
    • 2017-07-29
    • 2019-06-17
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多