【问题标题】:After installing the scr feature in karaf the activate method is called twice在 karaf 中安装 scr 功能后,激活方法被调用了两次
【发布时间】:2015-11-08 15:04:13
【问题描述】:

我正在尝试安装一个带有 apache-karaf 2.3.10 的 OSGi 包,我已经在 link 中发布了示例。我做了以下步骤

1. Downloaded apache-karaf version 2.3.10 
2. Executed the command features:install scr. Successfully installed scr. I have verified by executing scr:list
3. Installed all the bundles
4. Finally after starting all the bundles activate method in ExampleComponentFactoryManager  called twice and two objects are created. I have verified the same by executing the command scr:list
5. After uninstalling the scr feature the activate method in ExampleComponentFactoryManager called only once which is the expected behaviour.
6. Also i have noted that upto apache-karaf-2.3.10 while installing the scr feature it fetches from the online repo. But from 2.3.11 i am getting error because it tries to fetch it from my maven repository. The error is shown the console.

谁能告诉我 karaf 中的功能 scr 发生了什么? 因为有了 scr 功能,我可以看到 karaf 中有哪些可用的工厂和实例。这是预期的吗?

【问题讨论】:

    标签: java osgi apache-karaf karaf


    【解决方案1】:

    您能否检查一下是否有两个 felix scr 包正在运行。这将解释双重对象的创建。

    【讨论】:

    • 刚刚执行了“features:install scr”命令。我不知道内部实现。如果可能的话,我可以分享我的测试包,以便您可以在 2.3.10 以及其他版本中试用它。因为正如您所说,热部署文件夹中存在问题,我尝试使用命令 'install'file:' 安装捆绑包
    • 你能用 la -s 检查已安装的捆绑包,看看是否安装了多个 scr impl 吗?
    • 是的,有两个 org.apache.feilx.scr 一个是 1.8.2 版本,一个是 1.6.0。无论如何它不应该激活两次吧?
    • 因为 OSGi 支持安装相同版本的相同包。由此,如果存在相同捆绑包的两个版本,则将调用两次激活并导致对象创建重复,对吗?
    • 是的。通常安装一个包的两个版本不是什么大问题。在这种情况下,虽然 scr 包实现了扩展器模式。这意味着每个 scr 包都将适用于每个用户包,并且每个包都将创建所有对象。所以对于像 scr 这样的扩展包,只安装一个版本很重要。
    猜你喜欢
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多